Skip to content

ldconfig warns about truncated libraries #44

Closed

Description

@darealshinji

ldconfig puts a warning on files that were modified with patchelf:

djcj patchelf-master $ sudo src/patchelf --set-rpath /usr/lib /usr/lib/x86_64-linux-gnu/libx264.so.142
djcj patchelf-master $ LANG=C sudo ldconfig
/sbin/ldconfig.real: file /usr/lib/x86_64-linux-gnu/libx264.so.142 is truncated

djcj patchelf-master $ 

Activity

  1. darealshinji commented on Nov 10, 2014

    @darealshinji
    ContributorAuthor

    The sections .dynsym and .dynstr are moved to the end of the file. Originally .shstrtab was the last section. That might cause the trouble.

  2. AaronDMarasco-VSI commented on Sep 23, 2015

    @AaronDMarasco-VSI
    Contributor

    I am getting the same error when using the --set-soname option on 63296c4.

  3. sjackman commented on May 8, 2017

    @sjackman

    I'm seeing this error as well. Do you have a fix or workaround?

  4. AaronDMarasco-VSI commented on May 8, 2017

    @AaronDMarasco-VSI
    Contributor

    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().

  5. sjackman commented on May 8, 2017

    @sjackman

    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.

  6. darealshinji commented on May 9, 2017

    @darealshinji
    ContributorAuthor

    @AaronDMarasco-VSI Can you provide said custom patch?

  7. AaronDMarasco-VSI commented on May 9, 2017

    @AaronDMarasco-VSI
    Contributor

    @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.

  8. Narthorn commented on Jul 10, 2017

    @Narthorn

    It looks like ldconfig expects .dynstr to be in the first LOAD segment (elf/readelf.c in glibc), although I don't know why.

  9. darealshinji commented on Feb 20, 2018

    @darealshinji
    ContributorAuthor

    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.

  10. sjackman commented on Feb 20, 2018

    @sjackman

    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!

  11. Des-Nerger commented on Apr 21, 2018

    @Des-Nerger

    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:

    --- patchelf_orig.cc	2018-04-21 15:39:40.057741000 +1000
    +++ patchelf.cc	2018-04-21 16:16:20.097747164 +1000
    @@ -618,6 +618,12 @@
         s.resize(size);
         replacedSections[sectionName] = s;
     
    +    if (sectionName==".dynstr" && replacedSections.find(".shstrtab")==replacedSections.end()) {
    +        Elf_Shdr & shdr = findSection(".shstrtab");
    +        s = std::string((char *) contents + rdi(shdr.sh_offset), rdi(shdr.sh_size));
    +        replacedSections[".shstrtab"] = s;
    +    }
    +
         return replacedSections[sectionName];
     }

    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.

  12. Flow86 commented on Apr 24, 2018

    @Flow86

    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

    RUNPATH string offset not contained in string table
    
  13. davidvandebunte commented on Jun 13, 2018

    @davidvandebunte

    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.

  14. averelld commented on Dec 8, 2018

    @averelld

    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:

    • 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)
  15. rcombs commented on Mar 30, 2019

    @rcombs

    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.

  16. averelld commented on Mar 30, 2019

    @averelld

    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.

  17. haampie commented on Mar 31, 2020

    @haampie
    Contributor

    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

  18. mikhailnov commented on Apr 7, 2020

    @mikhailnov

    This problem exists in glibc 2.30 but does not in glibc 2.31, so this has probably been fixed in glibc upstream.

  19. mikhailnov commented on Apr 7, 2020

    @mikhailnov
    [root@rosa-2019 lib64]# ldconfig -V | head -n 1
    ldconfig (GNU libc) 2.31
    [root@rosa-2019 lib64]# ldconfig -l libstdc++-gcc10.so.6.0.28
    [root@rosa-2019 lib64]# 
    
    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
    
  20. haampie commented on Apr 7, 2020

    @haampie
    Contributor

    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 😅

  21. AaronDMarasco commented on Apr 7, 2020

    @AaronDMarasco

    then we don't have to worry

    <cries in CentOS 7>

  22. domenkozar commented on Jun 4, 2020

    @domenkozar
    Member

    Given this is fixed in glibc I'm closing this issue.

  23. sjackman commented on Jun 4, 2020

    @sjackman

    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)

  24. noloader commented on Jul 20, 2020

    @noloader

    Also see ldconfig and file xxx is truncated in Ubuntu's Launchpad.

  25. added a commit that references this issue on Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions