[llvm] [AArch64, ELF] Allow implicit $d/$x at section beginning (PR #99718)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 09:34:44 PDT 2024


smithp35 wrote:

Apologies for the delay in responding.

I'm uncomfortable with symbols defined at the end of the section as these fall through into the following section. I have seen that cause trouble before with 0 sized sections as contradictory mapping symbols at the same address are not well defined by the ABI. While it is true that the most likely implementation of a linker would order mapping symbols such that a trailing mapping symbol would get sorted before a mapping symbol at offset 0 in the next section; I'm not sure we can guarantee it, for example a non-stable sort of the symbols by address could break that. I also know of at least one linker that tries to optimize mapping symbols by removing redundant mapping symbols that will give an error message if it spots two contradictory mapping symbols at the same address.

I think it would be better to just omit the trailing $x mapping symbol as I expect it would cause more problems than it will solve. As `-foptimize-mapsyms` is opt-in and not the default, a user could be responsible for dealing with any corner-cases that arise with $d as the last mapping symbol in code-sections. For clang it looks like this is very rare. It is more common in GCC as it uses literal pools for -mcmodel=large. Clang uses 4 mov instructions instead. For what it is worth a colleague of mine is looking into adding execute-only support in AArch64, this largely means leaving code-generation alone, but giving an error if data is used in an executable section, this would guarantee no corner cases.

Going back to the ABI perhaps it would be worth looking at symbols rather than sections. Essentially can we make a symbol of type STT_FUNC with bit 0 clear (thinking of Morello, which uses 1 for C64 instructions) an implicit $x and a symbol of type STT_OBJECT an implicit $d, with all other symbols being neutral? This would solve the trailing $d problem for compiled code and well written assembly code (people are lazy about setting the type of symbols).



https://github.com/llvm/llvm-project/pull/99718


More information about the llvm-commits mailing list