Ld: Using -rpath,$ORIGIN inside a shared library (recursive)

Asked
Active3 hr before
Viewed126 times

7 Answers

libraryusing
90%

Basically, this is two questions into one - because if I can list all symbols exported within a system, along with their shared library path, then I could simply grep that output. ,To find where the symbols resolve to.,So, what to do about shared library symbols? Reading through [gcc-help] Re: finding the library in which symbol is defined.; I tried something like this:,Given a symbol _ZN6Kopete6Global10PropertiesC2Ev, where is this?

Examples:

nm - g / usr / lib / blah.a
readelf - Ws / usr / lib / blah.so

Given a symbol _ZN6Kopete6Global10PropertiesC2Ev, where is this?

scanelf - l - s _ZN6Kopete6Global10PropertiesC2Ev | grep _ZN6Kopete6Global10PropertiesC2Ev

which yields:

ET_DYN _ZN6Kopete6Global10PropertiesC2Ev / usr / lib64 / libkopete.so .4 .11 .4
load more v
88%

The Implicit Rules section follows. This contains all the built-in and user-defined pattern rules in make’s database. Again, for those rules defined in a file, a comment indicates the file and line number:,The makefile part is the name of the makefile or include file in which the error occurred. The next part is the line number where the error occurred, followed by three asterisks and, finally, the error message.,The final defensive programming technique is simply to make disabling the @ command modifier easy by using it through a make variable, rather than literally:,To use it, just set the list of variables to print on the command line, and include the debug target:

$(warning A top - level warning)

FOO: = $(warning Right - hand side of a simple variable) bar
BAZ = $(warning Right - hand side of a recursive variable) boo

$(warning A target) target: $(warning In a prerequisite list) makefile $(BAZ)
$(warning In a command script)
ls
$(BAZ):
$ make
makefile: 1: A top - level warning
makefile: 2: Right - hand side of a simple variable
makefile: 5: A target
makefile: 5: In a prerequisite list
makefile: 5: Right - hand side of a recursive variable
makefile: 8: Right - hand side of a recursive variable
makefile: 6: In a command script
ls
makefile
REQUIRED_DIRS = ...
   _MKDIRS: = $(shell
      for d in $(REQUIRED_DIRS);\ do\
         [
            [-d $$d]
         ] || mkdir - p $$d;\
      done)

$(objects): $(sources)
# GNU Make 3.80
# Copyright(C) 2002 Free Software Foundation, Inc.
# This is free software;
see the source
for copying conditions.
# There is NO warranty;
not even
for MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
normal command execution occurs here

# Make data base, printed on Thu Apr 29 20: 58: 13 2004

# Variables
   ...
   # Directories
   ...
   # Implicit Rules
   ...
   # Pattern - specific variable values
   ...
   # Files
   ...
   # VPATH Search Paths
# automatic
   <
   D = $(patsubst % /,%,$(dir $<))
      # environment EMACS_DIR = C: /usr/emacs - 21.3 .50 .7 #
      default CWEAVE = cweave # makefile(from `../mp3_player/makefile', line 35)
CPPFLAGS = $(addprefix -I ,$(include_dirs))
# makefile (from `.. / ch07 - separate - binaries / makefile ', line 44)
         RM: = rm - f # makefile(from `../mp3_player/makefile', line 14)
define make-library
  libraries += $1
  sources   += $2

  $1: $(call source-to-object,$2)
        $(AR) $(ARFLAGS) $$@ $$^
endef
% .c % .h: % .y
# commands to execute(from `../mp3_player/makefile', line 73):
        $(YACC.y) --defines $<
        $(MV) y.tab.c $*.c
        $(MV) y.tab.h $*.h

%: %.c
#  commands to execute (built-in):
        $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@

%.o: %.c
#  commands to execute (built-in):
        $(COMPILE.c) $(OUTPUT_OPTION) $<
% .c % .h: YYLEXFLAG: = -d %
   .c % .h: % .y
$(YACC.y) --defines $ <
   $(MV) y.tab.c $ * .c
$(MV) y.tab.h $ * .h
# Pattern - specific variable values

   %
   .c:
   # makefile(from `Makefile', line 1)
# YYLEXFLAG := -d
# variable set hash-table stats:
# Load=1/16=6%, Rehash=0, Collisions=0/1=0%

%.h :
# makefile (from `
      Makefile ', line 1)
      # YYLEXFLAG: = -d # variable set hash - table stats:
      # Load = 1 / 16 = 6 % , Rehash = 0, Collisions = 0 / 1 = 0 %

      # 2 pattern - specific variable values
# Not a target:
   .p.o:
   # Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# commands to execute(built - in ):
   $(COMPILE.p) $(OUTPUT_OPTION) $ <

   lib / ui / libui.a: lib / ui / ui.o
# Implicit rule search has not been done.
# Last modified 2004 - 04 - 01 22: 04: 09.515625
# File has been updated.
# Successfully updated.
# commands to execute(from `../mp3_player/lib/ui/module.mk', line 3):
        ar rv $@ $^

lib/codec/codec.o: ../mp3_player/lib/codec/codec.c ../mp3_player/lib/codec/codec.c ..
/mp3_player/include/codec/codec.h
#  Implicit rule search has been done.
#  Implicit/static pattern stem: `
      lib / codec / codec '
      # Last modified 2004 - 04 - 01 22: 04: 08.40625 # File has been updated.# Successfully updated.# commands to execute(built - in ):
      $(COMPILE.c) $(OUTPUT_OPTION) $ <
$ make--warn - undefined - variables - n
makefile: 35: warning: undefined variable MAKECMDGOALS
makefile: 45: warning: undefined variable CFLAGS
makefile: 45: warning: undefined variable TARGET_ARCH
   ...
   makefile: 35: warning: undefined variable MAKECMDGOALS
make: warning: undefined variable CFLAGS
make: warning: undefined variable TARGET_ARCH
make: warning: undefined variable CFLAGS
make: warning: undefined variable TARGET_ARCH
   ...
   make: warning: undefined variable LDFLAGS
make: warning: undefined variable TARGET_ARCH
make: warning: undefined variable LOADLIBES
make: warning: undefined variable LDLIBS
File all does not exist.
File app / player / play_mp3 does not exist.
File app / player / play_mp3.o does not exist.
Must remake target app / player / play_mp3.o.
gcc..... / mp3_player / app / player / play_mp3.c
Successfully remade target file app / player / play_mp3.o.
File all does not exist.
Considering target file app / player / play_mp3.
File app / player / play_mp3 does not exist.
Considering target file app / player / play_mp3.o.
File app / player / play_mp3.o does not exist.
Pruning file.. / mp3_player / app / player / play_mp3.c.
Pruning file.. / mp3_player / app / player / play_mp3.c.
Pruning file.. / mp3_player / include / player / play_mp3.h.
Finished prerequisites of target file app / player / play_mp3.o.
Must remake target app / player / play_mp3.o.
gcc..... / mp3_player / app / player / play_mp3.c
Successfully remade target file app / player / play_mp3.o.
Pruning file app / player / play_mp3.o.
File all does not exist.
File app / player / play_mp3 does not exist.
Looking
for an implicit rule
for app / player / play_mp3.
Trying pattern rule with stem play_mp3.
Trying implicit prerequisite app / player / play_mp3.o.
Found an implicit rule
for app / player / play_mp3.
File app / player / play_mp3.o does not exist.
Looking
for an implicit rule
for app / player / play_mp3.o.
Trying pattern rule with stem play_mp3.
Trying implicit prerequisite app / player / play_mp3.c.
Found prerequisite app / player / play_mp3.c as VPATH.. / mp3_player / app / player /
   play_mp3.c
Found an implicit rule
for app / player / play_mp3.o.
Must remake target app / player / play_mp3.o.
gcc..... / mp3_player / app / player / play_mp3.c
Successfully remade target file app / player / play_mp3.o.
Got a SIGCHLD;
1 unreaped children.
gcc..... / mp3_player / app / player / play_mp3.c
Putting child 0x10033800(app / player / play_mp3.o) PID 576 on the chain.
Live child 0x10033800(app / player / play_mp3.o) PID 576
Got a SIGCHLD;
1 unreaped children.
Reaping winning child 0x10033800 PID 576
Removing child 0x10033800 PID 576 from chain.
load more v
72%

library: Load a shared library on the fly, Load a library dynamically rather than using @Library syntax. You may use global variables defined in the library thereafter: ,libraryResource: Load a resource file from a shared library,Pipeline: Shared Groovy Libraries library: Load a shared library on the fly libraryResource: Load a resource file from a shared library

Load a library dynamically rather than using @Library syntax. You may use global variables defined in the library thereafter:

library 'mylib@master'
usefulFunction()

You may also load classes defined in the library by selecting their fully-qualified names like properties on the return value of this step, then call static methods or call constructors as if they were a method named new:

def utils = library('mylib').com.mycorp.jenkins.Utils.new(this)
utils.handyStuff()
load more v
65%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , 1 @m4l490n, if your discrepancy name is linux-vdso.so, this is a virtual library injected by the kernel into every process. It exists as a file only during kernel build, and then just stored inside the kernel. It is speeding up unprivileged calls as time() that do not really require an expensive mode transition. – kkm Oct 8 '20 at 8:29 ,The objdump tool can tell you this information. If you invoke objdump with the -x option, to get it to output all headers then you'll find the shared object dependencies right at the start in the "Dynamic Section".,You can use readelf to explore the ELF headers. readelf -d will list the direct dependencies as NEEDED sections.

You can use readelf to explore the ELF headers. readelf -d will list the direct dependencies as NEEDED sections.

 $ readelf - d elfbin

 Dynamic section at offset 0xe30 contains 22 entries:
    Tag Type Name / Value
 0x0000000000000001(NEEDED) Shared library: [libssl.so .1 .0 .0]
 0x0000000000000001(NEEDED) Shared library: [libc.so .6]
 0x000000000000000c(INIT) 0x400520
 0x000000000000000d(FINI) 0x400758
    ...
load more v
75%

For details of in-depth Linux/UNIX system programming training courses that I teach, look here. , HTML rendering created 2021-08-27 by Michael Kerrisk, author of The Linux Programming Interface, maintainer of the Linux man-pages project.

load more v
40%

Here is how the complete simple makefile looks when you use a variable for the object files: ,if variable was defined in a makefile. ,The file name extension for installed section 2 man pages. ,The file name extension for installed section 1 man pages.

load more v
22%

Regardless of which tool is in use, Valgrind takes control of your program before it starts. Debugging information is read from the executable and associated libraries, so that error messages and other outputs can be phrased in terms of source code locations, when appropriate.,However, fpscr[FPRF] is not set after each operation. That could be done but would give measurable performance overheads, and so far no need for it has been found., Such marker lines facilitate searching for errors and/or extracting errors in an output file that contain valgrind errors mixed with the program output. ,Errors are reported before the associated operation actually happens. For example, if you're using Memcheck and your program attempts to read from address zero, Memcheck will emit a message to this effect, and your program will then likely die with a segmentation fault.

You invoke Valgrind like this:

valgrind[valgrind - options] your - prog[your - prog - options]

The most important option is --tool which dictates which Valgrind tool to run. For example, if want to run the command ls -l using the memory-checking tool Memcheck, issue this command:

valgrind--tool = memcheck ls - l
load more v

Other "library-using" queries related to "Ld: Using -rpath,$ORIGIN inside a shared library (recursive)"