You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For me with --set-soname, I am pretty sure replaceSection() is broken. Since I am always shortening the name, I have a custom patch that detects I am calling it and does the name replacement directly in memory by zeroing out the unused bytes at the end. The original code always assumed the new name was longer and called replaceSection().
I use --set-interpreter and --set-rpath and they usually get longer for me. Thanks for the tip though. I could maybe arrange it for them to get shorter rather than longer. Probably not always though.
@darealshinji It doesn't fix replaceSection(); instead it bypasses it in a very specific way that would be pretty useless for most people. I compile the .so with the suffix "_s" but then later rename it to without so need to change that name explicitly.
Here's the patch, but like I said, extremely specific and unlikely to be helpful for public consumption.
I may be wrong but I think I read somewhere that ELF specification doesn't require where the sections are written, so I guess readelf's and ld.so's behavior are right while ldconfig's behavior is a bug.
Good sleuthing, Dimitry! A patch upstream to Glibc is definitely warranted. In the mean time, a workaround for patchelf that ensures that .dynstr is the first STRTAB section would be useful. Thanks for sorting out the root cause!
I don't think the issue is caused by the wrong order of .dynstr and .shstrtab. I forced patchelf to overwrite the .shstrtab section too, with the following hack:
The sections became reversed again but it didn't make ldconfig happy. Meanwhile, they had been written to a new separate segment LOAD at the end (which can be seen by readelf -l), so I suspect the @Narthorn 's version is more plausible.
This is probably better described as an "ldconfig error" rather than an "ldconfig warning" as in the title. It prints to standard error and the dynamic loader can't find the libraries afterwards.
Basically as @Narthorn said, the .dynstr vaddr is resolved against the first LOAD segment, which doesn't work on any libs where patchelf called rewriteSections, because that moves .dynstr to the last LOAD segment.
Additionally I don't think it's possible to fix this in patchelf itself in the current implementation:
If soname gets longer, or rpath is added, dynstr cannot fit at it's old location.
LOAD segments have to be referenced in order of ascending vaddr in the header (I checked the specs)
This seems like it's actually a bug in ldconfig. process_elf_file is assuming that the entire file will be mapped contiguously, which of course isn't required by the spec. It'd probably be worth filing against glibc.
user@pay2:/tmp$ LC_ALL=C ldconfig -V | head -n 1
ldconfig (Ubuntu GLIBC 2.30-0ubuntu2.1) 2.30
user@pay2:/tmp$ LC_ALL=C ldconfig -l libstdc++-gcc10.so.6.0.28
/sbin/ldconfig.real: file libstdc++-gcc10.so.6.0.28 is truncated
/sbin/ldconfig.real: No link created since soname could not be found for libstdc++-gcc10.so.6.0.28
Activity
darealshinji commentedon Nov 10, 2014
The sections
.dynsymand.dynstrare moved to the end of the file. Originally.shstrtabwas the last section. That might cause the trouble.AaronDMarasco-VSI commentedon Sep 23, 2015
I am getting the same error when using the
--set-sonameoption on 63296c4.sjackman commentedon May 8, 2017
I'm seeing this error as well. Do you have a fix or workaround?
AaronDMarasco-VSI commentedon May 8, 2017
For me with
--set-soname, I am pretty surereplaceSection()is broken. Since I am always shortening the name, I have a custom patch that detects I am calling it and does the name replacement directly in memory by zeroing out the unused bytes at the end. The original code always assumed the new name was longer and calledreplaceSection().sjackman commentedon May 8, 2017
I use
--set-interpreterand--set-rpathand they usually get longer for me. Thanks for the tip though. I could maybe arrange it for them to get shorter rather than longer. Probably not always though.darealshinji commentedon May 9, 2017
@AaronDMarasco-VSI Can you provide said custom patch?
AaronDMarasco-VSI commentedon May 9, 2017
@darealshinji It doesn't fix
replaceSection(); instead it bypasses it in a very specific way that would be pretty useless for most people. I compile the .so with the suffix "_s" but then later rename it to without so need to change that name explicitly.Here's the patch, but like I said, extremely specific and unlikely to be helpful for public consumption.
Narthorn commentedon Jul 10, 2017
It looks like ldconfig expects .dynstr to be in the first LOAD segment (elf/readelf.c in glibc), although I don't know why.
darealshinji commentedon Feb 20, 2018
I may be wrong but I think I read somewhere that ELF specification doesn't require where the sections are written, so I guess readelf's and ld.so's behavior are right while ldconfig's behavior is a bug.
sjackman commentedon Feb 20, 2018
Good sleuthing, Dimitry! A patch upstream to Glibc is definitely warranted. In the mean time, a workaround for
patchelfthat ensures that.dynstris the firstSTRTABsection would be useful. Thanks for sorting out the root cause!Des-Nerger commentedon Apr 21, 2018
I don't think the issue is caused by the wrong order of
.dynstrand.shstrtab. I forced patchelf to overwrite the.shstrtabsection too, with the following hack:The sections became reversed again but it didn't make ldconfig happy. Meanwhile, they had been written to a new separate segment
LOADat the end (which can be seen byreadelf -l), so I suspect the @Narthorn 's version is more plausible.Flow86 commentedon Apr 24, 2018
is there any solution to fix this or work around that problem?
could it be that some string is missing?
if I try to read the rpath via "chrpath" utility, Ill get
davidvandebunte commentedon Jun 13, 2018
This is probably better described as an "ldconfig error" rather than an "ldconfig warning" as in the title. It prints to standard error and the dynamic loader can't find the libraries afterwards.
--set-soname: overwrite in place if it fits (NixOS#44)
averelld commentedon Dec 8, 2018
Here's a small patch in case anyone else needs ldconfig to work:
NixOS/nixpkgs@d44a939#diff-64b83ddc8edce55f9aff3a4e639ce3bd
Basically as @Narthorn said, the .dynstr vaddr is resolved against the first LOAD segment, which doesn't work on any libs where patchelf called rewriteSections, because that moves .dynstr to the last LOAD segment.
Additionally I don't think it's possible to fix this in patchelf itself in the current implementation:
rcombs commentedon Mar 30, 2019
This seems like it's actually a bug in ldconfig.
process_elf_fileis assuming that the entire file will be mapped contiguously, which of course isn't required by the spec. It'd probably be worth filing against glibc.averelld commentedon Mar 30, 2019
It is, here's a bug report filed in December: https://sourceware.org/bugzilla/show_bug.cgi?id=23964. But it's probably not a priority, or at least there hasn't been any activity.
haampie commentedon Mar 31, 2020
Not sure if this is the right place to ask, but does anybody know if this issue is being fixed in ldconfig upstream?
As I understand it, this is an issue already noted 10 years ago, e.g. here https://nix-dev.science.uu.narkive.com/q6Ww5fyO/ldconfig-problem-with-patchelf-and-64-bit-libs
mikhailnov commentedon Apr 7, 2020
This problem exists in glibc 2.30 but does not in glibc 2.31, so this has probably been fixed in glibc upstream.
mikhailnov commentedon Apr 7, 2020
haampie commentedon Apr 7, 2020
Thanks, give it 3 more years and Ubuntu 18.04 is end of life, then we don't have to worry about this issue anymore 😅
AaronDMarasco commentedon Apr 7, 2020
<cries in CentOS 7>
domenkozar commentedon Jun 4, 2020
Given this is fixed in glibc I'm closing this issue.
sjackman commentedon Jun 4, 2020
This issue has been fixed in glibc 2.31. #44 (comment)
glibc 2.31 is included in Ubuntu 20.04 and Fedora 32, but nothing older, in particular no stable release of either Debian or CentOS.
https://github.com/Linuxbrew/brew/wiki/Bottles#glibc-version
(for my and other's information)
noloader commentedon Jul 20, 2020
Also see ldconfig and file xxx is truncated in Ubuntu's Launchpad.
Take libmali.so directly from rockchip repo