This is an archive of the discontinued LLVM Phabricator instance.

[ELF][Hexagon] Add support for TLS IE relocations
ClosedPublic

Authored by sidneym on Dec 6 2019, 12:30 PM.

Diff Detail

Event Timeline

sidneym created this revision.Dec 6 2019, 12:30 PM
MaskRay added inline comments.Dec 6 2019, 12:48 PM
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.

sidneym updated this revision to Diff 236124.Jan 3 2020, 1:37 PM

merge ie and iegot relocations
put the testcase into just a single file.

MaskRay added inline comments.Jan 3 2020, 4:59 PM
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.

sidneym updated this revision to Diff 236410.Jan 6 2020, 10:37 AM

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.

I'd like to ask some questions which can help understand the situation better.

  • Does Hexagon have a binutils port or an alternative linker?

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.

I'd like to ask some questions which can help understand the situation better.

  • Does Hexagon have a binutils port or an alternative linker?

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.

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

I'd like to ask some questions which can help understand the situation better.

  • Does Hexagon have a binutils port or an alternative linker?

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.

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.

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.

sidneym updated this revision to Diff 236587.Jan 7 2020, 7:42 AM

Add config->hasStaticTlsModel in R_GOT case.

sidneym updated this revision to Diff 236591.Jan 7 2020, 7:58 AM

Move hasStaticTlsModel from R_GOT case to the suggested R_GOTPLT case.

MaskRay added inline comments.Jan 7 2020, 2:45 PM
lld/test/ELF/hexagon-tls-ie.s
6

## for comments.

8

%t.so for shared objects.

Users expect %t.o and %t.so to be related, so don't add 2 suffix.

9

no-show-raw-insn to disable hex pairs in llvm-objdump -d output

34

llvm-readelf -x .got to test .got . See riscv-tls-ie.s

62

align

sidneym updated this revision to Diff 236875.Jan 8 2020, 11:36 AM
sidneym marked 4 inline comments as done.

Address testcase issues.

MaskRay accepted this revision.Jan 8 2020, 11:46 AM
This revision is now accepted and ready to land.Jan 8 2020, 11:46 AM
This revision was automatically updated to reflect the committed changes.