Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

using older libc for linking process [solved]

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
DaggyStyle
Watchman
Watchman
User avatar
Posts: 5969
Joined: Wed Mar 22, 2006 6:57 am

using older libc for linking process [solved]

  • Quote

Post by DaggyStyle » Sun Jun 24, 2012 1:03 pm

hello.

I have a binary that needed to link against older version of libc, I have all the needed libs in a custom path, how can I force gcc to use that path?
both compiler and lib are 64 bit.

Thanks,
Last edited by DaggyStyle on Tue Jun 26, 2012 3:06 pm, edited 1 time in total.
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Top
wcg
Guru
Guru
Posts: 588
Joined: Tue Jan 06, 2009 7:05 pm

  • Quote

Post by wcg » Mon Jun 25, 2012 7:25 am

Well, Gentoo has the slot mechanism. I see it in use, but I have not
explored how it works in detail.

There is also LD_LIBRARY_PATH, mainly used for testing according
to the standard documentation on it, but you could wrap your
executable in a script that prepends the path to your other libc
to the standard LD_LIBRARY_PATH:

Code: Select all

#!/bin/sh

LD_LIBRARY_PATH=[custom path to alt libc]:${LD_LIBRARY_PATH}
exec /usr/bin/[name].bin
Rename the executable in /usr/bin (or wherever) to "[name].bin",
and call the script "[name]" (the name of the program that
needs the alternative libc).

Standard documentation:
http://tldp.org/HOWTO/Program-Library-H ... aries.html
(Section 3.3..1)
man ld-linux.so
(The glibc info pages say that executables not running with the uid
of the user executing the command ignore LD_LIBRARY_PATH.)

The linker's -rpath option may solve your problem without LD_LIBRARY_PATH
manipulation. man ld, search for "-rpath".

Finally, you can statically link the binary to your alt libc. (Pass a custom LDFLAGS
to the emerge on the command line.)
Last edited by wcg on Tue Jun 26, 2012 3:21 pm, edited 1 time in total.
TIA
Top
DaggyStyle
Watchman
Watchman
User avatar
Posts: 5969
Joined: Wed Mar 22, 2006 6:57 am

  • Quote

Post by DaggyStyle » Mon Jun 25, 2012 9:47 am

wcg wrote:Well, Gentoo has the slot mechanism. I see it in use, but I have not
explored how it works in detail.

There is also LD_LIBRARY_PATH, mainly used for testing according
to the standard documentation on it, but you could wrap your
executable in a script that prepends the path to your other libc
to the standard LD_LIBRARY_PATH:

Code: Select all

#!/bin/sh

LD_LIBRARY_PATH=[custom path to alt libc]:${LD_LIBRARY_PATH}
exec /usr/bin/[name].bin
Rename the executable in /usr/bin (or wherever) to "[name].bin,
and call the script "[name]" (the name of the program that
needs the alternative libc).

Standard documentation:
http://tldp.org/HOWTO/Program-Library-H ... aries.html
(Section 3.3..1)
man ld-linux.so
(The glibc info pages say that executables not running with the uid
of the user executing the command ignore LD_LIBRARY_PATH.)

The linkers -rpath option may solve your problem without LD_LIBRARY_PATH
manipulation. man ld, search for "-rpath".

Finally, you can statically link the binary to your alt libc. (Pass a custom LDFLAGS
to the emerge on the command line.)
statically linking fails when it comes to incompatible glibc implementations.
I don't want to base it on portage as I want to prevent issues when a specific lib get cleared from the tree.
I'll check the other possibilities, thanks.
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Top
Genone
Retired Dev
Retired Dev
User avatar
Posts: 9656
Joined: Fri Mar 14, 2003 6:02 pm
Location: beyond the rim

  • Quote

Post by Genone » Mon Jun 25, 2012 10:12 am

If gcc is the issue you may have to tell it to ignore the standard libraries and specify your custom libc via -lc and -L/path/to/your/libc.so:
-nostartfiles
Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used.
-nodefaultlibs
Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker. The standard startup files are used normally, unless -nostartfiles is used. The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.
-nostdlib
Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker. The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

One of the standard libraries bypassed by -nostdlib and -nodefaultlibs is libgcc.a, a library of internal subroutines that GCC uses to overcome shortcomings of particular machines, or special needs for some languages.

In most cases, you need libgcc.a even when you want to avoid other standard libraries. In other words, when you specify -nostdlib or -nodefaultlibs you should usually specify -lgcc as well. This ensures that you have no unresolved references to internal GCC library subroutines. (For example, __main, used to ensure C ++ constructors will be called.)
Top
DaggyStyle
Watchman
Watchman
User avatar
Posts: 5969
Joined: Wed Mar 22, 2006 6:57 am

  • Quote

Post by DaggyStyle » Mon Jun 25, 2012 11:19 am

Genone wrote:If gcc is the issue you may have to tell it to ignore the standard libraries and specify your custom libc via -lc and -L/path/to/your/libc.so:
-nostartfiles
Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used.
-nodefaultlibs
Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker. The standard startup files are used normally, unless -nostartfiles is used. The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.
-nostdlib
Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker. The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove". These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

One of the standard libraries bypassed by -nostdlib and -nodefaultlibs is libgcc.a, a library of internal subroutines that GCC uses to overcome shortcomings of particular machines, or special needs for some languages.

In most cases, you need libgcc.a even when you want to avoid other standard libraries. In other words, when you specify -nostdlib or -nodefaultlibs you should usually specify -lgcc as well. This ensures that you have no unresolved references to internal GCC library subroutines. (For example, __main, used to ensure C ++ constructors will be called.)
that is exactly what I've done but I still don't have full info if it worked from our qa so I still keep the thread unsolved.
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Top
DaggyStyle
Watchman
Watchman
User avatar
Posts: 5969
Joined: Wed Mar 22, 2006 6:57 am

  • Quote

Post by DaggyStyle » Tue Jun 26, 2012 3:06 pm

ok, using -nodefaultlibs with -L and -l works well.
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Top
wcg
Guru
Guru
Posts: 588
Joined: Tue Jan 06, 2009 7:05 pm

  • Quote

Post by wcg » Tue Jun 26, 2012 3:43 pm

Just out of curiousity, how old is this libc that it needs
to link to? What version? What parts of current stable
libc break it?
TIA
Top
DaggyStyle
Watchman
Watchman
User avatar
Posts: 5969
Joined: Wed Mar 22, 2006 6:57 am

  • Quote

Post by DaggyStyle » Tue Jun 26, 2012 8:35 pm

wcg wrote:Just out of curiousity, how old is this libc that it needs
to link to? What version? What parts of current stable
libc break it?
2.4

if I compile it staticllay it breaks on 2.7 and above.
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Top
Post Reply

8 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic