diff options
author | Csanád Hajdú <csanad.hajdu@arm.com> | 2025-02-14 09:56:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-14 08:56:07 +0000 |
commit | a190f15d2b84e873ee978d0e6f04bf36e8f17583 (patch) | |
tree | d02e8ea243956d90ad88ea7cdcd48a309d9d2348 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | be827051924375f7c10a7380902e01a0b10ce860 (diff) | |
download | llvm-a190f15d2b84e873ee978d0e6f04bf36e8f17583.zip llvm-a190f15d2b84e873ee978d0e6f04bf36e8f17583.tar.gz llvm-a190f15d2b84e873ee978d0e6f04bf36e8f17583.tar.bz2 |
[AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (1/3) (#125687)
Add support for the new SHF_AARCH64_PURECODE ELF section flag:
https://github.com/ARM-software/abi-aa/pull/304
The general implementation follows the existing one for ARM targets.
Generating object files with the `SHF_AARCH64_PURECODE` flag set is
enabled by the `+execute-only` target feature.
Related PRs:
* Clang: https://github.com/llvm/llvm-project/pull/125688
* LLD: https://github.com/llvm/llvm-project/pull/125689
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 9f44f8b..be2f5fb 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -547,7 +547,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) { return ELF::SHT_PROGBITS; } -static unsigned getELFSectionFlags(SectionKind K) { +static unsigned getELFSectionFlags(SectionKind K, const Triple &T) { unsigned Flags = 0; if (!K.isMetadata() && !K.isExclude()) @@ -559,8 +559,12 @@ static unsigned getELFSectionFlags(SectionKind K) { if (K.isText()) Flags |= ELF::SHF_EXECINSTR; - if (K.isExecuteOnly()) - Flags |= ELF::SHF_ARM_PURECODE; + if (K.isExecuteOnly()) { + if (T.isAArch64()) + Flags |= ELF::SHF_AARCH64_PURECODE; + else if (T.isARM() || T.isThumb()) + Flags |= ELF::SHF_ARM_PURECODE; + } if (K.isWriteable()) Flags |= ELF::SHF_WRITE; @@ -845,7 +849,7 @@ static MCSection *selectExplicitSectionGlobal(const GlobalObject *GO, // Infer section flags from the section name if we can. Kind = getELFKindForNamedSection(SectionName, Kind); - unsigned Flags = getELFSectionFlags(Kind); + unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple()); auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM); Flags |= ExtraFlags; @@ -952,7 +956,7 @@ static MCSection *selectELFSectionForGlobal( MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal( const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { - unsigned Flags = getELFSectionFlags(Kind); + unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple()); // If we have -ffunction-section or -fdata-section then we should emit the // global value to a uniqued section specifically for it. @@ -972,7 +976,7 @@ MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal( MCSection *TargetLoweringObjectFileELF::getUniqueSectionForFunction( const Function &F, const TargetMachine &TM) const { SectionKind Kind = SectionKind::getText(); - unsigned Flags = getELFSectionFlags(Kind); + unsigned Flags = getELFSectionFlags(Kind, TM.getTargetTriple()); // If the function's section names is pre-determined via pragma or a // section attribute, call selectExplicitSectionGlobal. if (F.hasSection()) |