Support TLS IE relocations
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
lld/test/ELF/hexagon-tls-ie.s | ||
---|---|---|
2 | See ppc32-tls-ie.s and riscv-tls-ie.s You need both a -shared test and an executable (-no-pie, it is the default) test. No separate input file in Inputs/ is necessary. |
lld/ELF/Arch/Hexagon.cpp | ||
---|---|---|
123 | Is it really R_GOT (absolute), instead of R_GOT_PC (PC-relative)? R_GOT is really only used by i386 because it lacks PC-relative instructions. This is a quite serious deficiency so x86_64 ISA and ABI have fixed the problem. (AArch64 does also use R_GOT but it has bool AArch64::usesOnlyLowPageBits(RelType type), so using R_GOT is not a problem.) | |
lld/test/ELF/hexagon-tls-ie.s | ||
63 | Use -NEXT is applicable. CHECK-RELA-NEXT: is too long. So you can consider using RELA as the check-prefix. |
Update Check names.
I confirmed that R_GOT is correct. The ABI is worded as:
R_HEX_IE_16_X ... (G + GOT) Unsigned Truncate
and I verified the output with an internal linker, hexagon-link.
I'd like to ask some questions which can help understand the situation better.
- Does Hexagon have a binutils port or an alternative linker?
- Is -pie and -shared used a lot on Hexagon?
- How is Hexagon's dynamic loader ld.so implemented? Is the source code available?
- How is TLS going to be used on Hexagon?
- Is text relocations acceptable?
- Is it really impossible to use a PC-relative GOT address load on Hexagon? R_GOT on EM_386 has severe limitations. EM_X86_64 fixed these issues. (I don't want to see newer architectures behave like it.)
I shall also mention that this is unfortunate.
bool canRelax = config->emachine != EM_ARM &&
config->emachine != EM_RISCV;
RISC-V TLS has several problems. Its design/implementation was copied from ARM/MIPS. The two architectures really do not provide the best reference for TLS implementations. The RISC-V TLS implementation has several defects. I've reported a few bugs on the binutils bugzilla.
The binutils port was never made public. The internal linker can be downloaded with a click-thu license agreement, the same one needed to get to the ABI spec. That linker is a branch of mclinker.
- Is -pie and -shared used a lot on Hexagon?
-pie isn't but shared is.
- How is Hexagon's dynamic loader ld.so implemented? Is the source code available?
The code isn't yet available from Qualcomm but we have a port of MUSL and I don't think much more than adding the #defines to reloc.h and the files dlsym.s/tlsdesc.s was done. Nothing weird for hexagon.
- How is TLS going to be used on Hexagon?
There isn't anything out of the ordinary in how it is used and it is necessary for C++11 support.
- Is text relocations acceptable?
No. The reason I needed to add the -z notext in the -shared test was because technically the wrong relocations were being used. I did that so that I could condense the IE patch into a single file testcase.
- Is it really impossible to use a PC-relative GOT address load on Hexagon? R_GOT on EM_386 has severe limitations. EM_X86_64 fixed these issues. (I don't want to see newer architectures behave like it.)
The R_HEX_IE_GOT... are used for shared/pic code. As far as I know the R_HEX_IE_32_6_X/16_X.. are used only when building static code. The ABI has examples for both of these IE static and IE for PIC.
I shall also mention that this is unfortunate.
bool canRelax = config->emachine != EM_ARM &&
config->emachine != EM_RISCV;RISC-V TLS has several problems. Its design/implementation was copied from ARM/MIPS. The two architectures really do not provide the best reference for TLS implementations. The RISC-V TLS implementation has several defects. I've reported a few bugs on the binutils bugzilla.
Like @ruiu argued before, a click-thu license agreement may be unacceptable in many environments. I am also concerned whether a click-thru license agreement is considered 100% GPLv3 conformance.
- Is -pie and -shared used a lot on Hexagon?
-pie isn't but shared is.
- How is Hexagon's dynamic loader ld.so implemented? Is the source code available?
The code isn't yet available from Qualcomm but we have a port of MUSL and I don't think much more than adding the #defines to reloc.h and the files dlsym.s/tlsdesc.s was done. Nothing weird for hexagon.
The source code will be appreciated.
- How is TLS going to be used on Hexagon?
There isn't anything out of the ordinary in how it is used and it is necessary for C++11 support.
- Is text relocations acceptable?
No. The reason I needed to add the -z notext in the -shared test was because technically the wrong relocations were being used. I did that so that I could condense the IE patch into a single file testcase.
Not entirely wrong, and used in practice, e.g. libGL.so and libGLESv2.so use DT_STATIC_TLS. There are certain PC relative instructions, so R_GOT looks out-of-place to me. I hope this can be changed.
lld/ELF/Arch/Hexagon.cpp | ||
---|---|---|
137 | Add config->hasStaticTlsModel = true; if you use Initial Exec TLS model. And create a llvm-readelf -d test (see riscv-tls-ie.s). |
All hexagon work on binutils/gcc was done during the GPLv2 timeframe. The downloadable linker I'm referring to is a branch from the old mclinker project.
- Is -pie and -shared used a lot on Hexagon?
-pie isn't but shared is.
- How is Hexagon's dynamic loader ld.so implemented? Is the source code available?
The code isn't yet available from Qualcomm but we have a port of MUSL and I don't think much more than adding the #defines to reloc.h and the files dlsym.s/tlsdesc.s was done. Nothing weird for hexagon.
The source code will be appreciated.
I agree and will make sure you are notified when it is available.
- How is TLS going to be used on Hexagon?
There isn't anything out of the ordinary in how it is used and it is necessary for C++11 support.
- Is text relocations acceptable?
No. The reason I needed to add the -z notext in the -shared test was because technically the wrong relocations were being used. I did that so that I could condense the IE patch into a single file testcase.
Not entirely wrong, and used in practice, e.g. libGL.so and libGLESv2.so use DT_STATIC_TLS. There are certain PC relative instructions, so R_GOT looks out-of-place to me. I hope this can be changed.
Is it really R_GOT (absolute), instead of R_GOT_PC (PC-relative)?
R_GOT is really only used by i386 because it lacks PC-relative instructions. This is a quite serious deficiency so x86_64 ISA and ABI have fixed the problem. (AArch64 does also use R_GOT but it has bool AArch64::usesOnlyLowPageBits(RelType type), so using R_GOT is not a problem.)