Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 860888 - dev-util/patchelf-0.17.2 - patchelf.cc: error: DT_MIPS_XHASH was not declared in this scope
Summary: dev-util/patchelf-0.17.2 - patchelf.cc: error: DT_MIPS_XHASH was not declared...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo musl team
URL:
Whiteboard:
Keywords: PATCH, PullRequest
Depends on:
Blocks:
 
Reported: 2022-07-25 07:15 UTC by Toralf Förster
Modified: 2023-04-27 07:46 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge-info.txt (emerge-info.txt,17.59 KB, text/plain)
2022-07-25 07:15 UTC, Toralf Förster
Details
dev-util:patchelf-0.15.0:20220725-002453.log (dev-util:patchelf-0.15.0:20220725-002453.log,5.28 KB, text/plain)
2022-07-25 07:15 UTC, Toralf Förster
Details
emerge-history.txt (emerge-history.txt,129.77 KB, text/plain)
2022-07-25 07:15 UTC, Toralf Förster
Details
environment (environment,71.20 KB, text/plain)
2022-07-25 07:15 UTC, Toralf Förster
Details
etc.portage.tar.bz2 (etc.portage.tar.bz2,11.10 KB, application/x-bzip)
2022-07-25 07:15 UTC, Toralf Förster
Details
logs.tar.bz2 (logs.tar.bz2,4.66 KB, application/x-bzip)
2022-07-25 07:15 UTC, Toralf Förster
Details
temp.tar.bz2 (temp.tar.bz2,19.74 KB, application/x-bzip)
2022-07-25 07:15 UTC, Toralf Förster
Details
glibc-dt-mips-xhash.patch (glibc-dt-mips-xhash.patch,903 bytes, patch)
2023-03-01 06:17 UTC, Tom Gillespie
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Toralf Förster gentoo-dev 2022-07-25 07:15:34 UTC
Making all in src
make[1]: Entering directory '/var/tmp/portage/dev-util/patchelf-0.15.0/work/patchelf-0.15.0/src'
x86_64-gentoo-linux-musl-g++ -DPACKAGE_NAME=\"patchelf\" -DPACKAGE_TARNAME=\"patchelf\" -DPACKAGE_VERSION=\"0.15.0\" -DPACKAGE_STRING=\"patchelf\ 0.15.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"patchelf\" -DVERSION=\"0.15.0\" -I.    -Wall -std=c++17 -D_FILE_OFFSET_BITS=64     -pipe -march=native -fno-diagnostics-color -O2 -D_GLIBCXX_ASSERTIONS -c -o patchelf.o patchelf.cc
patchelf.cc: In member function 'void ElfFile<Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym, Elf_Verneed, Elf_Versym>::rewriteHeaders(Elf_Addr)':
patchelf.cc:999:33: error: 'DT_MIPS_XHASH' was not declared in this scope; did you mean 'DT_MIPS_FLAGS'?
  999 |             } else if (d_tag == DT_MIPS_XHASH) {
      |                                 ^~~~~~~~~~~~~

  -------------------------------------------------------------------

  This is an unstable amd64 chroot image at a tinderbox (==build bot)
  name: 17.0_musl_hardened-j4-20220723-104412

  -------------------------------------------------------------------

gcc-config -l:
 [1] x86_64-gentoo-linux-musl-12.1.1 *
clang/llvm (if any):
clang version 14.0.6
Target: x86_64-gentoo-linux-musl
Thread model: posix
InstalledDir: /usr/lib/llvm/14/bin
/usr/lib/llvm/14
14.0.6
Python 3.10.5
Available Rust versions:
  [1]   rust-1.62.1 *
The following VMs are available for generation-2:
*)	Eclipse Temurin JDK 17.0.3_p7 [openjdk-bin-17]
Available Java Virtual Machines:
  [1]   openjdk-bin-17  system-vm

php cli:

  HEAD of ::gentoo
commit 9d500c5c8ee8d1989e6db8829ef928471bf57448
Author: Repository mirror & CI <repomirrorci@gentoo.org>
Date:   Sun Jul 24 23:31:43 2022 +0000

    2022-07-24 23:31:42 UTC

emerge -qpvO dev-util/patchelf
[ebuild  N    ] dev-util/patchelf-0.15.0
Comment 1 Toralf Förster gentoo-dev 2022-07-25 07:15:35 UTC
Created attachment 794180 [details]
emerge-info.txt
Comment 2 Toralf Förster gentoo-dev 2022-07-25 07:15:36 UTC
Created attachment 794183 [details]
dev-util:patchelf-0.15.0:20220725-002453.log
Comment 3 Toralf Förster gentoo-dev 2022-07-25 07:15:37 UTC
Created attachment 794186 [details]
emerge-history.txt
Comment 4 Toralf Förster gentoo-dev 2022-07-25 07:15:39 UTC
Created attachment 794189 [details]
environment
Comment 5 Toralf Förster gentoo-dev 2022-07-25 07:15:40 UTC
Created attachment 794192 [details]
etc.portage.tar.bz2
Comment 6 Toralf Förster gentoo-dev 2022-07-25 07:15:41 UTC
Created attachment 794195 [details]
logs.tar.bz2
Comment 7 Toralf Förster gentoo-dev 2022-07-25 07:15:42 UTC
Created attachment 794198 [details]
temp.tar.bz2
Comment 8 Agostino Sarubbo gentoo-dev 2022-12-21 09:56:40 UTC
tinderbox_musl has reproduced this issue with version 0.17.0 - Updating summary.
Comment 9 Darkii 2023-02-08 22:36:34 UTC
reproduced with dev-util/patchelf-0.17.2

Why does ebuild deletes elf.h where DT_MIPS_XHASH is defined?
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-02-09 05:00:57 UTC
(In reply to Darkii from comment #9)
> reproduced with dev-util/patchelf-0.17.2
> 
> Why does ebuild deletes elf.h where DT_MIPS_XHASH is defined?

That's not necessarily the cause of the error, as it would be odd if it just didn't-include-it-if-it-doesn't-exist (although it's possible w/ e.g. _has_include).

Anyway, you got me curious, and it dates back to..

```
   commit f18acb2c34480ef41a70c60fda80dcf21e5397b0
   Author: Justin Lecher <jlec@gentoo.org>
   Date:   Mon Feb 4 15:59:31 2013 +0000
  
       dev-util/patchelf: Use system header, thanks fedora; respect CC, CFLAGS an LDFLAGS in test binaries
  
       (Portage version: 2.2.0_alpha161/cvs/Linux x86_64, signed Manifest commit with key 70EB7916)
```

but it's possible that musl's elf.h, as opposed to glibc's, lacks DT_MIPS_XHASH. I dunno if DT_MIPS_XHASH is a standard thing or not. I assume no.
Comment 11 Agostino Sarubbo gentoo-dev 2023-02-14 08:34:02 UTC
tinderbox_musl has reproduced this issue with version 0.17.2 - Updating summary.
Comment 12 Tom Gillespie 2023-03-01 06:09:40 UTC
Looking at the musl elf.h it does not define DT_MIPS_XHASH. The patch at https://github.com/tgbugs/dockerfiles/blob/d4de50f82493189212287f131059dd7640cdd8d4/source.org?plain=1#L1849-L1863 is sufficient to resolve the issue without apparent side effects. I'm sure there is probably a better/more correct solution in patchelf.cc involving a #define or something, but for now this might be sufficient.
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-03-01 06:11:32 UTC
(In reply to Tom Gillespie from comment #12)
> Looking at the musl elf.h it does not define DT_MIPS_XHASH. The patch at
> https://github.com/tgbugs/dockerfiles/blob/
> d4de50f82493189212287f131059dd7640cdd8d4/source.org?plain=1#L1849-L1863 is
> sufficient to resolve the issue without apparent side effects. I'm sure
> there is probably a better/more correct solution in patchelf.cc involving a
> #define or something, but for now this might be sufficient.

We'd want a patch which we can apply unconditionally.

Anyway, it should be fine to guard it with #ifdef __GLIBC__ given it's purely a glibc construct (modified hash type).
Comment 14 Tom Gillespie 2023-03-01 06:17:34 UTC
Created attachment 855328 [details, diff]
glibc-dt-mips-xhash.patch

Something like this maybe?
Comment 15 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-03-01 06:36:16 UTC
lgtm

there is a problem in that if you build on musl (not cross compiling), you won't be able to use it to modify a MIPS glibc-linked binary, but I feel like that's a pretty niche issue, especially given it doesn't build at all on musl anyway, and the nature of this tool is kind of brittle anyway -- so I think this is ok.
Comment 16 hugegameartgd 2023-03-07 12:38:26 UTC
Also see https://github.com/NixOS/patchelf/pull/471
Comment 17 hugegameartgd 2023-03-11 17:13:31 UTC
Is there a reason for removing src/elf.h in https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-util/patchelf/patchelf-0.17.2.ebuild#n17 ?
Otherwise changing the ebuild to use bundled elf.h for musl libc would also work.

```
diff --git a/dev-util/patchelf/patchelf-0.17.2.ebuild b/dev-util/patchelf/patchelf-0.17.2.ebuild
index ef24854c86..b35af485c9 100644
--- a/dev-util/patchelf/patchelf-0.17.2.ebuild
+++ b/dev-util/patchelf/patchelf-0.17.2.ebuild
@@ -14,7 +14,7 @@ LICENSE="GPL-3"
 
 src_prepare() {
        default
-       rm src/elf.h || die
+       use elibc_musl || rm src/elf.h || die
 
        sed -i \
                -e 's:-Werror::g' \
```
Comment 18 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-03-11 17:17:54 UTC
(In reply to hugegameartgd from comment #17)
> Is there a reason for removing src/elf.h in
> https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-util/patchelf/patchelf-0.
> 17.2.ebuild#n17 ?
> Otherwise changing the ebuild to use bundled elf.h for musl libc would also
> work.

Have you read the above? I address that..
Comment 19 hugegameartgd 2023-03-11 17:34:04 UTC
(In reply to Sam James from comment #10)
> (In reply to Darkii from comment #9)
> > reproduced with dev-util/patchelf-0.17.2
> > 
> > Why does ebuild deletes elf.h where DT_MIPS_XHASH is defined?
> 
> That's not necessarily the cause of the error, as it would be odd if it just
> didn't-include-it-if-it-doesn't-exist (although it's possible w/ e.g.
> _has_include).
> 
I guess the file should be bundled for glibc compatibility on musl systems as it fixes compilation, does void linux and other musl related projects unbundle the elf.h header file?
Comment 20 Larry the Git Cow gentoo-dev 2023-04-27 07:46:42 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3baf1a6f70fba59102f8e1eeb46cb8291e4b9a8a

commit 3baf1a6f70fba59102f8e1eeb46cb8291e4b9a8a
Author:     LinuxUserGD <hugegameartgd@gmail.com>
AuthorDate: 2023-04-15 16:29:53 +0000
Commit:     James Le Cuirot <chewi@gentoo.org>
CommitDate: 2023-04-27 07:45:53 +0000

    Add define for DT_MIPS_XHASH
    
    Closes: https://bugs.gentoo.org/860888
    Signed-off-by: LinuxUserGD <hugegameartgd@gmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/30604
    Signed-off-by: James Le Cuirot <chewi@gentoo.org>

 dev-util/patchelf/files/patchelf-glibc-dt-mips-xhash.patch | 9 +++++++++
 dev-util/patchelf/patchelf-0.18.0.ebuild                   | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)