This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] DWARF: do not generate AT_location for thread local
ClosedPublic

Authored by lliu0 on Feb 27 2018, 11:14 PM.

Details

Summary

AArch64 ELF ABI does not define a static relocation type for TLS offset within a module, which makes it impossible for compiler to generate a valid DW_AT_location content for thread local variables. Currently LLVM generates an invalid R_AARCH64_ABS64 relocation at the DW_AT_location field for a TLS variable. That causes trouble for linker because thread local variable does not have an absolute address at link time. AArch64 GCC solves the problem by not generating DW_AT_location for thread local variables. We should do the same in LLVM.

This fixes https://bugs.llvm.org/show_bug.cgi?id=21077.

Diff Detail

Repository
rL LLVM

Event Timeline

lliu0 created this revision.Feb 27 2018, 11:14 PM
lliu0 edited the summary of this revision. (Show Details)

Could the frontend just generate a description of the variable witohut a
location instead?

The problem is really a limitation of AArch64 ELF ABI. I don't think
frontend should change its behavior based on such low level target information.

Thanks,
Lei

Ping.

Could anyone help review this please?

Thanks,
Lei

I had a quick look at the PR last week after some people mentioned that they were seeing link errors in their project and were blaming the linker and not the compiler. I'm not a debug expert so it would be best to get someone else to look over the test case. I think the source code changes are probably the best that we can do right now.

To the best of my knowledge there is currently no way of expressing a relocation for the debug location in the AArch64 ABI. All the existing TLS relocations are with respect to instructions with small immediate fields, there is no equivalent to the DTPREL relocation for data that other Targets are using so there is no way of describing the location from debug data. At the moment I'm trying to work out if this is a limitation of the descriptor based TLS model that AArch64 uses or whether this is just an oversight in the design of the ABI. GCC for Arm does implement the descriptor based model with -mtls-model=gnu2, this uses the same relocation for debug as the non-descriptor based model; however I'm not confident that this is guaranteed to be correct.

I'm going to speak to some colleagues that work on GCC and will raise an issue on the AArch64 ABI if it is a missing feature. This might make it possible to remove this patch if linker and debugger support becomes available later.

Ping.

I think making the compiler not generate DW_AT_location for TLS variables is the best we can do with the current AArch64 ABI.

Thanks,
Lei

dblaikie added inline comments.Jul 30 2018, 6:39 PM
test/DebugInfo/AArch64/tls-at-location.ll
10 ↗(On Diff #136230)

I guess this is sufficient/avoids needing to pass a triple to llc directly?

& does that ensure ELF, not MachO?

21 ↗(On Diff #136230)

Strip out these attributes if they're not needed.

lliu0 updated this revision to Diff 158188.Jul 31 2018, 1:56 AM

Update test case to pass -mtriple=aarch64--linux-gnu to llc.

Rebase to LLVM trunk.

lliu0 marked 2 inline comments as done.Jul 31 2018, 1:57 AM

@aprantl @JDevlieghere - This looks good to me, but could you take a glance & see if it's reasonable for AArch64 (though this is for ELF, not MachO - but figure it might cut close enough you might want to check it)

@aprantl @JDevlieghere - This looks good to me, but could you take a glance & see if it's reasonable for AArch64 (though this is for ELF, not MachO - but figure it might cut close enough you might want to check it)

To be honest, I really don't know. @t.p.northover perhaps?

t.p.northover accepted this revision.Aug 1 2018, 7:58 AM

I think it's reasonable too.

This revision is now accepted and ready to land.Aug 1 2018, 7:58 AM
This revision was automatically updated to reflect the committed changes.