[compiler-rt] [compiler-rt] Add CMake option to enable execute-only code generation on AArch64 (PR #140555)

Csanád Hajdú via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 09:15:16 PDT 2025


Il-Capitano wrote:

> > > I don't think that this properly handles MachO.
> > 
> > 
> > Can you expand on this more? MachO doesn't have execute-only code AFAIK. This is intended for AArch64 ELF targets only.
> 
> These macros are not ELF specific is the issue. You are changing macros that are shared across all architectures and file formats. If you could scope this down somehow to not touch these global macros, that might be easier.

The change is adding a `.text` or `.section .text,"axy",unique,0` directive before the function definitions, which just makes sure we're in the `.text` section. The execute-only case is guarded by `defined(__aarch64__) && defined(__ELF__)`, so shouldn't affect any other targets. The alternative would be to change every AArch64 assembly file individually, but I don't think that would be better.

The cases where functions are put in differently named sections don't seem to use these macros anyways.

> > > Additionally, I don't understand the need for the `unique` flag on the section, nor the section id (`0`).
> > 
> > 
> > `unique,0` is needed because the assembler creates an implicit `.text` section with default flags. If we tried to just do `.section .text,"axy"`, we'd get the following error: `error: changed section flags for .text, expected: 0x6`. So the execute-only `.text` section needs to be different from the implicit `.text` section. The id `0` is arbitrary, but we need to provide something anyways.
> > This also matches what LLVM outputs when it generates execute-only code: https://godbolt.org/z/a8xa7qsxG
> 
> Ah, I see. I think that deserves a comment explaining why we need those flags are being added. I do wonder if we should simply drop the `unique,0` and instead build the builtins as `-ffunction-sections` instead as that places the text into a separate section.

You're right, I'll add a comment clarifying this. For dropping `unique,0` do you mean to add `.section .text.name` in the function definition macros? That could work to get rid of the `unique,0` suffix.

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


More information about the llvm-commits mailing list