What Is aLibrary?
Most people are familiar with
files (Dynamic Link Libraries) in Windows.
The Linux equivalent is a
file, a Shared Object, often referred to as just Library.
A library can be used by an app allowing that program to utilize functionality from outside its program code.
It is a way of sharing common goods and interests in most, if not all, operating systems.
Thelddtool is another handy tool to have in any more advanced Linux user toolbox.
what isltrace?
Theltraceutility/tool traces all library calls.
Alike to
, we can start a programunder(think about it like a hierarchy)ltrace.
It does so by intercepting and recording thedynamiclibrary calls made by the program being executed.
libraries not directly compiled into a program;dynamiclibraries.
Next we created a directory~/workspaceand jumped into it.
We then made three empty files using thetouchcommand, namely filesa,bandc.
This is not very useful this far.
Reasoning for a few seconds about howtarwill operate here will quickly reveal our next approach.
The avid reader may have also understood that thetarcommand internally would call thexzcommand.
The–xzoption passed to ourtarcommand line will ensure that thexzprogram is used for compression.
As such, we need to trace the child processes of the program running underltrace, i.e.tar.
The reason is that we want to specify this option toltraceand not to thetarcommand.
All options after thetarcommand aretarspecific options whereas-fis an option specific toltrace.
The output is a bit more interesting.
Handy and all good.
So, where are our library calls?
Let’s have a look.
If you are interested in learning more about redirection seeBash Automation and Scripting Basics (Part 3).
Now that we added the-Soption, we can see all libraries being accessed.
For example, we see/etc/ld.so.preloadbeing accessed.
in between, these will be shown inline at the moment they take place.
We installedltrace, set up a test environment, and executed someltracecommands with the most commonly used options.