[llvm] [PAC][CodeGen][ELF][AArch64] Support signed GOT (PR #105798)
Daniil Kovalev via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 02:24:13 PDT 2024
================
@@ -923,6 +928,22 @@ void AArch64AsmPrinter::emitEndOfAsmFile(Module &M) {
OutStreamer->addBlankLine();
}
+
+ // With signed ELF GOT enabled, the linker looks at the symbol type to
+ // choose between keys IA (for STT_FUNC) and DA (for other types). Symbols
+ // for functions not defined in the module have STT_NOTYPE type by default.
+ // This makes linker to emit signing schema with DA key (instead of IA) for
+ // corresponding R_AARCH64_AUTH_GLOB_DAT dynamic reloc. To avoid that, force
+ // all function symbols used in the module to have STT_FUNC type. See
+ // https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst#default-signing-schema
+ const auto *PtrAuthELFGOTFlag = mdconst::extract_or_null<ConstantInt>(
+ M.getModuleFlag("ptrauth-elf-got"));
+ if (PtrAuthELFGOTFlag && PtrAuthELFGOTFlag->getZExtValue() == 1)
+ for (const GlobalValue &GV : M.global_values())
+ if (!GV.use_empty() && GV.getValueType()->isFunctionTy() &&
----------------
kovdan01 wrote:
> Can it be simplified down to `isa<Function>(GV)`?
Yes, it can, thanks for suggestion! Fixed in cc9681063f645a808fec804253c7f0e598377b98
> Also, what happens with aliases?
Aliases must point to a definition (if I don't miss smth). Symbols for functions with definitions will anyway be marked as `STT_FUNC`. The point of the loop is to mark all function symbols which only have declarations as `STT_FUNC`. Yes, the loop also covers defined functions (not function aliases), but there is no issue in "double-marking" them - it'll not result in duplicate annotation in assembly. A test for alias to a defined function is present in llvm/test/CodeGen/AArch64/ptrauth-got-abuse.ll.
https://github.com/llvm/llvm-project/pull/105798
More information about the llvm-commits
mailing list