This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

how to compile a lower gcc/glibc version compatible binary?


I have a question on how to use high gcc version to compile and get a lower
gcc/glibc version compatible binary?

The scenario is I built a binary on debian sid with its gcc-5.2 and some high
glibc version, when I copy this binary to lower version debian system, it may
not run or complain some library version info not available, like

/lib/x86_64-linux-gnu/libtinfo.so.5: no version information available (required by /path/to/this-binary)

this is dumped with `readelf -V ...`

Version needs section '.gnu.version_r' contains 6 entries:
 Addr: 0x000000000042e770  Offset: 0x02e770  Link: 6 (.dynstr)
  000000: Version: 1  File: librt.so.1  Cnt: 1
  0x0010:   Name: GLIBC_2.2.5  Flags: none  Version: 13
  0x0020: Version: 1  File: libdl.so.2  Cnt: 1
  0x0030:   Name: GLIBC_2.2.5  Flags: none  Version: 9
  0x0040: Version: 1  File: libtinfo.so.5  Cnt: 1
  0x0050:   Name: NCURSES_TINFO_5.0.19991023  Flags: none  Version: 7
  0x0060: Version: 1  File: libpthread.so.0  Cnt: 2
  0x0070:   Name: GLIBC_2.3.2  Flags: none  Version: 5
  0x0080:   Name: GLIBC_2.2.5  Flags: none  Version: 4
  0x0090: Version: 1  File: libc.so.6  Cnt: 6
  0x00a0:   Name: GLIBC_2.14  Flags: none  Version: 12
  0x00b0:   Name: GLIBC_2.10  Flags: none  Version: 11
  0x00c0:   Name: GLIBC_2.3.4  Flags: none  Version: 10
  0x00d0:   Name: GLIBC_2.3  Flags: none  Version: 8
  0x00e0:   Name: GLIBC_2.3.2  Flags: none  Version: 6
  0x00f0:   Name: GLIBC_2.2.5  Flags: none  Version: 3
  0x0100: Version: 1  File: libm.so.6  Cnt: 1
  0x0110:   Name: GLIBC_2.2.5  Flags: none  Version: 2

I think the problem here is actually with library dependency, when built on
debian sid higher version of glibc, it generates some version info in the
'.gnu.version_r' section that caused unable to load on a lower version of
debian;

But I wonder does gcc have an option to support such need? in above case, with
what gcc option can I build a binary without linking to GLIBC_2.14 ? and
without NCURSES_TINFO_5.0.19991023? I found those are the two library symbols
missing on my target system, or where I want to run this binary;

the workaround is to use a lower debian version (same as the target) as the
development system, but what if I want the better generated code by gcc-5.2 ?
it's also against the encouragement for people to upgrade and test new
compiler; one solution may be to compile a gcc-5.2 with target system lower
glibc version, while most people still like to use a distro default compiler I
think, may not have ability or do not want the burden to maintain a customized
gcc/glibc sysroot;

So does gcc support such requirement to build a binary without linking symbols
higher than a specific lib version? If not, can we request such a feature?

I have looked up some documentation did some online research, haven't found a
simple answer yet, http://stackoverflow.com/a/2858996/5672998 has shown a
.symver based solution, but its using __asm__ instructions is really
inconvenient


Thanks,
- Derek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]