GHC's Linker Should Support Relocation Type 42
As per: https://github.com/DanielG/ghc-mod/issues/762#issuecomment-213743585
"gas >= 2.26 uses some new relocation types (in particular type 42, aka R_X86_64_REX_GOTPCRELX), which are not supported by ghc's linker."
This causes problems when linking in libs with certain sorts of c bits via the GHC API (at the very least).
Support should be added.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |
- Show closed items
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- gershomb changed weight to 5
changed weight to 5
- gershomb added Tbug Trac import labels
added Tbug Trac import labels
Trac metadata
Trac field Value Component Compiler → Runtime System (Linker) - Tamar Christina assigned to @Phyx
assigned to @Phyx
- Developer
Thanks for the report, this should be simple enough to fix
- Developer
Trac metadata
Trac field Value Differential revisions - → D2303 - thoughtpolice changed milestone to %8.0.2
changed milestone to %8.0.2
- thoughtpolice changed weight to 7
changed weight to 7
I'm bumping the priority for this to 'high' (as GHC is technically broken on a new binutils in the static linker configuration) and moving it to 8.0.2.
Trac metadata
Trac field Value Priority normal → high I have "GNU assembler (GNU Binutils for Debian) 2.26" on my Debian system. but have not yet hit this issue. Is there a test case?
Tried this:
$ cabal get cipher-aes $ cd cipher-aes-0.2.11 $ cabal sandbox init $ cabal install --dependencies-only --enable-tests $ cabal install $ cabal exec -- ghci -i:Tests Tests/Tests.hs ghci > main GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Ok, modules loaded: Crypto.Cipher.AES, Main, KATECB, KATCBC, KATXTS, KATGCM, KATOCB3. ghci > main ghc: panic! (the 'impossible' happened) (GHC version 7.10.3 for x86_64-unknown-linux): Loading temp shared object failed: /tmp/ghcc0a8_0/libghc_9.so: undefined symbol: aes_decrypt_ecb Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
That doesn't seem to be quite the same problem.
- Developer
I haven't written a testcase since you need
binutils-2.26
for it to trigger and I don't think I can force the test only then.In any case, simplest case to reproduce this is to compile
GHC
withDYNAMIC_GHC_PROGRAMS=NO
I use this assembly file as input:
# x86_64 # as as_test.s -o as_test.o && objdump -Dr as_test.o # ghc --interactive hs_test as_test.o .text .globl foo foo: push %rbp mov %rsp, %rbp mov msg@GOTPCREL(%rip), %rdi call puts@PLT pop %rbp ret .data msg: .ascii "Hello World!\0" len = . - msg
Which with
[phyx@localhost ~]$ as --version GNU assembler (GNU Binutils) 2.26.20160125
returns the expected relocation
[phyx@localhost ~]$ as as_test.s -o as_test.o && objdump -Dr as_test.o as_test.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <foo>: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 48 8b 3d 00 00 00 00 mov 0x0(%rip),%rdi # b <foo+0xb> 7: R_X86_64_REX_GOTPCRELX msg-0x4 b: e8 00 00 00 00 callq 10 <foo+0x10> c: R_X86_64_PLT32 puts-0x4 10: 5d pop %rbp 11: c3 retq Disassembly of section .data: 0000000000000000 <msg>: 0: 48 rex.W 1: 65 6c gs insb (%dx),%es:(%rdi) 3: 6c insb (%dx),%es:(%rdi) 4: 6f outsl %ds:(%rsi),(%dx) 5: 20 57 6f and %dl,0x6f(%rdi) 8: 72 6c jb 76 <len+0x69> a: 64 21 00 and %eax,%fs:(%rax)
Before the patch it crashes as expected
[phyx@localhost ~]$ ghc/inplace/bin/ghc-stage2 --interactive as_test.o hs_test.hs GHCi, version 8.1.20160604: http://www.haskell.org/ghc/ :? for help ghc-stage2: as_test.o: unhandled ELF relocation(RelA) type 42 linking extra libraries/objects failed
And after the patch
GHCi, version 8.1.20160604: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( hs_test.hs, interpreted ) Ok, modules loaded: Main. *Main> main Hello World!
- Tamar Christina closed
closed
- Developer
NOTE: The bindist for elf platforms need to be build using a system that has
glibc >= 2.23
in order forelf.h
to contain these constants and for GHC to then be able to use them.Trac metadata
Trac field Value Resolution Unresolved → ResolvedFixed - Tamar Christina mentioned in commit 0d963caf
mentioned in commit 0d963caf
- Thomas Miedema reopened
reopened
Trac metadata
Trac field Value Resolution ResolvedFixed → Unresolved - Thomas Miedema added 1 deleted label
added 1 deleted label
@bgamari, is the a big enough issue to consider doing a 7.10.4 release?
Quoting @erikd in https://phabricator.haskell.org/D2303#67070:
I'm pretty sure that will be handled by the Linux distros. They wouldn't ship an GNU
as
until theirglibc
handled these new relocations.We have our first victim of this assumption: https://github.com/snowleopard/hadrian/issues/259#issuecomment-224618414.