Merge ~bhill/epics-base:shared-rpath-independent-of-static-build into ~epics-core/epics-base/+git/epics-base:7.0

Proposed by Bruce Hill
Status: Merged
Approved by: Andrew Johnson
Approved revision: 4f0c9c97c6265f2a37ace54824ad4cf3bc453203
Merged at revision: ddb79a37bc51acd9bab58bcfe98260a3ba45a41d
Proposed branch: ~bhill/epics-base:shared-rpath-independent-of-static-build
Merge into: ~epics-core/epics-base/+git/epics-base:7.0
Diff against target: 26 lines (+6/-6)
1 file modified
configure/os/CONFIG.Common.linuxCommon (+6/-6)
Reviewer Review Type Date Requested Status
Andrew Johnson Approve
Review via email: mp+373243@code.launchpad.net

Commit message

Shared lib rpath should not depend on whether or not static libs are also being built.

EPICS build system supports building both static and shared libs.
Useful for modules which might get used in both static and dynamically linked apps.
Without this fix shared libs only get rpath if LINKER_USE_RPATH=YES and STATIC_BUILD=NO.

Static builds don't pay any attention to rpath linker flags so no need to disable.

To post a comment you must log in.
Revision history for this message
rivers (rivers) wrote :

I believe this is a problem I have been noticing recently when using base 7.0.3.

When I build ADPointGrey statically it does not find the vendor library I installed and linked with libflycapture.so.2. Here is the output of ldd.

ADPointGrey>ldd iocs/pointGreyIOC/bin/linux-x86_64/pointGreyApp

        linux-vdso.so.1 => (0x00007ffc83dd4000)

        libflycapture.so.2 => not found

        libX11.so.6 => /lib64/libX11.so.6 (0x00007f8ef5c62000)

        libXext.so.6 => /lib64/libXext.so.6 (0x00007f8ef5a50000)

        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f8ef5834000)

        libreadline.so.6 => /lib64/libreadline.so.6 (0x00007f8ef55ee000)

        librt.so.1 => /lib64/librt.so.1 (0x00007f8ef53e6000)

        libdl.so.2 => /lib64/libdl.so.2 (0x00007f8ef51e2000)

        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f8ef4edb000)

        libm.so.6 => /lib64/libm.so.6 (0x00007f8ef4bd9000)

        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f8ef49c3000)

        libc.so.6 => /lib64/libc.so.6 (0x00007f8ef45f6000)

        libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f8ef43ce000)

        /lib64/ld-linux-x86-64.so.2 (0x00007f8ef5fa0000)

        libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f8ef41a4000)

        libXau.so.6 => /lib64/libXau.so.6 (0x00007f8ef3fa0000)

I have to to add ADPointGrey/lib/linux-x86_64 to my LD_LIBRARY_PATH.

corvette:~/devel/areaDetector/ADPointGrey>setenv LD_LIBRARY_PATH /home/epics/devel/areaDetector/ADPointGrey/lib/linux-x86_64

Now when I run ldd it finds the library:

corvette:~/devel/areaDetector/ADPointGrey>ldd iocs/pointGreyIOC/bin/linux-x86_64/pointGreyApp

        linux-vdso.so.1 => (0x00007ffe5e4ed000)

        libflycapture.so.2 => /home/epics/devel/areaDetector/ADPointGrey/lib/linux-x86_64/libflycapture.so.2 (0x00007efcdedc2000)

        libX11.so.6 => /lib64/libX11.so.6 (0x00007efcdea84000)

...

Revision history for this message
rivers (rivers) wrote :

I just applied Bruce's change to CONFIG.Common.linuxCommon and rebuilt ADPointGrey. It did not fix my problem.

corvette:~/devel/areaDetector/ADPointGrey>ldd iocs/pointGreyIOC/bin/linux-x86_64/pointGreyApp
        linux-vdso.so.1 => (0x00007ffee58ac000)
        libflycapture.so.2 => not found
        libX11.so.6 => /lib64/libX11.so.6 (0x00007f8359bba000)
        libXext.so.6 => /lib64/libXext.so.6 (0x00007f83599a8000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f835978c000)
        libreadline.so.6 => /lib64/libreadline.so.6 (0x00007f8359546000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f835933e000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f835913a000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f8358e33000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f8358b31000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f835891b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f835854e000)
        libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f8358326000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f8359ef8000)
        libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f83580fc000)
        libXau.so.6 => /lib64/libXau.so.6 (0x00007f8357ef8000)

I am pretty sure I did not have to set LD_LIBRARY_PATH in these circumstances on 3.15 or 3.14.

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

Mark, if you want to understand what flags were used to build a binary, then the output of 'readelf' is quite helpful. eg. the RUNPATH entry shows the -rpath which was passed to the linker, and the NEEDED entries are the direct library dependencies (the -l passed to the linker).

$ readelf -d bin/linux-x86_64/caget |head

Dynamic section at offset 0x8d90 contains 32 entries:
  Tag Type Name/Value
 0x0000000000000001 (NEEDED) Shared library: [libca.so.4.13.3]
 0x0000000000000001 (NEEDED) Shared library: [libCom.so.3.17.4]
 0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/../../lib/linux-x86_64]

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

This branch will introduce a (likely trivial) merge conflict with https://code.launchpad.net/~epics-core/epics-base/+git/make/+merge/359132

Revision history for this message
rivers (rivers) wrote :
Download full text (3.1 KiB)

> Mark, if you want to understand what flags were used to build a binary, then the output of 'readelf' is quite helpful.

Thanks. Here is the readelf output
corvette:pointGreyIOC/bin/linux-x86_64>readelf -d pointGreyApp

Dynamic section at offset 0x12caa90 contains 34 entries:
  Tag Type Name/Value
 0x0000000000000001 (NEEDED) Shared library: [libflycapture.so.2]
 0x0000000000000001 (NEEDED) Shared library: [libX11.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libXext.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED) Shared library: [libreadline.so.6]
 0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
 0x000000000000000c (INIT) 0x5cae30
 0x000000000000000d (FINI) 0x12b3b5c
 0x0000000000000019 (INIT_ARRAY) 0x1829d58
 0x000000000000001b (INIT_ARRAYSZ) 1240 (bytes)
 0x000000000000001a (FINI_ARRAY) 0x182a230
 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
 0x000000006ffffef5 (GNU_HASH) 0x400298
 0x0000000000000005 (STRTAB) 0x4bac68
 0x0000000000000006 (SYMTAB) 0x42b748
 0x000000000000000a (STRSZ) 967743 (bytes)
 0x000000000000000b (SYMENT) 24 (bytes)
 0x0000000000000015 (DEBUG) 0x0
 0x0000000000000003 (PLTGOT) 0x18cb000
 0x0000000000000002 (PLTRELSZ) 14064 (bytes)
 0x0000000000000014 (PLTREL) RELA
 0x0000000000000017 (JMPREL) 0x5c7740
 0x0000000000000007 (RELA) 0x5b3130
 0x0000000000000008 (RELASZ) 83472 (bytes)
 0x0000000000000009 (RELAENT) 24 (bytes)
 0x000000006ffffffe (VERNEED) 0x5b2fc0
 0x000000006fffffff (VERNEEDNUM) 7
 0x000000006ffffff0 (VERSYM) 0x5a70a8
 0x0000000000000000 (NULL) 0x0

Note that it does not contain a RUNPATH at all, which explains the problem.

This is happening even though I have applied Bruce's patch and my CONFIG.Common.linuxCommon contains this:
SHRLIBDIR_RPATH_LDFLAGS_YES = $(SHRLIB_DEPLIB_DIRS:%=-Wl,-rpath,%)
SHRLIBDIR_LDFLAGS += \
    $(SHRLIBDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH))

Let me explain what I am trying to do:
- Build a static executable
- Building with the vendor library which is only provided as a shared library.

My Makefile contains this:
# We use PROD_SYS_LIBS even though libflycapture.so is in the ADPointGrey tree
# because we are doing static build but the file is a .so file, not a .a file.
PROD_SYS_LIBS_Linux += flycapture

So I have to use PROD_SYS_LIBS_Linux, rather than PROD_LIBS, because PROD_LIBS only looks for a .a file if building statically.

I want RUNPATH to include the path to that vendor library that I installed in ADPointGrey...

Read more...

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

Ah. Bruce has changed SHRLIBDIR_RPATH_LDFLAGS_ which is used when linking shared libraries. A matching change is needed just below to PRODDIR_RPATH_LDFLAGS_ which is use for executables.

Revision history for this message
rivers (rivers) wrote :
Download full text (5.9 KiB)

I made that change:

corvette:base-7.0.3/configure/os>git diff CONFIG.Common.linuxCommon
diff --git a/configure/os/CONFIG.Common.linuxCommon b/configure/os/CONFIG.Common.linuxCommon
index 965de09..ab00e4b 100644
--- a/configure/os/CONFIG.Common.linuxCommon
+++ b/configure/os/CONFIG.Common.linuxCommon
@@ -24,14 +24,14 @@ STATIC_LDFLAGS_NO=
 STATIC_LDLIBS_YES= -Wl,-Bdynamic

 # Set runtime path for shared libraries if USE_RPATH=YES and STATIC_BUILD=NO
-SHRLIBDIR_RPATH_LDFLAGS_YES_NO = $(SHRLIB_DEPLIB_DIRS:%=-Wl,-rpath,%)
+SHRLIBDIR_RPATH_LDFLAGS_YES = $(SHRLIB_DEPLIB_DIRS:%=-Wl,-rpath,%)
 SHRLIBDIR_LDFLAGS += \
- $(SHRLIBDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH)_$(STATIC_BUILD))
+ $(SHRLIBDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH))

 # Set runtime path for products if USE_RPATH=YES and STATIC_BUILD=NO
-PRODDIR_RPATH_LDFLAGS_YES_NO = $(PROD_DEPLIB_DIRS:%=-Wl,-rpath,%)
+PRODDIR_RPATH_LDFLAGS_YES = $(PROD_DEPLIB_DIRS:%=-Wl,-rpath,%)
 PRODDIR_LDFLAGS += \
- $(PRODDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH)_$(STATIC_BUILD))
+ $(PRODDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH))

 # Link libraries controlled by COMMANDLINE_LIBRARY
 # The newest Linux versions only need readline, older ones need both

That fixed the problem:

corvette:pointGreyIOC/bin/linux-x86_64>readelf -d pointGreyApp

Dynamic section at offset 0x12caa70 contains 35 entries:
  Tag Type Name/Value
 0x0000000000000001 (NEEDED) Shared library: [libflycapture.so.2]
 0x0000000000000001 (NEEDED) Shared library: [libX11.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libXext.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED) Shared library: [libreadline.so.6]
 0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
 0x000000000000000f (RPATH) Library rpath: [/home/epics/devel/areaDetector-3-7/ADPointGrey/lib/linux-x86_64:/home/epics/devel/areaDetector-3-7/ADPointGrey/iocs/pointGreyIOC/lib/linux-x86_64:/home/epics/devel/areaDetector-3-7/ADCore/lib/linux-x86_64:/home/epics/devel/areaDetector-3-7/ADSupport/lib/linux-x86_64:/home/epics/devel/asyn-4-36/lib/linux-x86_64:/home/epics/devel/autosave-5-10/lib/linux-x86_64:/home/epics/devel/busy-1-7-2/lib/linux-x86_64:/home/epics/devel/calc-3-7-3/lib/linux-x86_64:/home/epics/devel/devIocStats-3-1-16/lib/linux-x86_64:/home/epics/devel/seq-2-2-5/lib/linux-x86_64:/home/epics/devel/sscan-2-11-3/lib/linux-x86_64:/usr/local/epics-devel/base-7.0.3/lib/linux-x86_64]
 0x000000000000000c (INIT) 0x5cb0c0
 0x000000000000000d (FINI) 0x12b3dec
 0x0000000000000019 (INIT_ARRAY) 0x1829d38
 0x000000000000001b (INIT_ARRAYSZ) 1240 (bytes)
 0x000000000000001a (FINI_ARRAY) 0x182a210
 0x000000000000001c (FINI_ARRAYSZ) ...

Read more...

Revision history for this message
Bruce Hill (bhill) wrote :

Michael, thanks for finding the exe fix!
I've updated the pull request accordingly.

Revision history for this message
Andrew Johnson (anj) wrote :

Group 10/4: No issues.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/configure/os/CONFIG.Common.linuxCommon b/configure/os/CONFIG.Common.linuxCommon
2index 965de09..5405be7 100644
3--- a/configure/os/CONFIG.Common.linuxCommon
4+++ b/configure/os/CONFIG.Common.linuxCommon
5@@ -23,15 +23,15 @@ STATIC_LDFLAGS_YES= -Wl,-Bstatic
6 STATIC_LDFLAGS_NO=
7 STATIC_LDLIBS_YES= -Wl,-Bdynamic
8
9-# Set runtime path for shared libraries if USE_RPATH=YES and STATIC_BUILD=NO
10-SHRLIBDIR_RPATH_LDFLAGS_YES_NO = $(SHRLIB_DEPLIB_DIRS:%=-Wl,-rpath,%)
11+# Set runtime path for shared libraries if LINKER_USE_RPATH=YES
12+SHRLIBDIR_RPATH_LDFLAGS_YES = $(SHRLIB_DEPLIB_DIRS:%=-Wl,-rpath,%)
13 SHRLIBDIR_LDFLAGS += \
14- $(SHRLIBDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH)_$(STATIC_BUILD))
15+ $(SHRLIBDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH))
16
17-# Set runtime path for products if USE_RPATH=YES and STATIC_BUILD=NO
18-PRODDIR_RPATH_LDFLAGS_YES_NO = $(PROD_DEPLIB_DIRS:%=-Wl,-rpath,%)
19+# Set runtime path for products if LINKER_USE_RPATH=YES
20+PRODDIR_RPATH_LDFLAGS_YES = $(PROD_DEPLIB_DIRS:%=-Wl,-rpath,%)
21 PRODDIR_LDFLAGS += \
22- $(PRODDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH)_$(STATIC_BUILD))
23+ $(PRODDIR_RPATH_LDFLAGS_$(LINKER_USE_RPATH))
24
25 # Link libraries controlled by COMMANDLINE_LIBRARY
26 # The newest Linux versions only need readline, older ones need both

Subscribers

People subscribed via source and target branches