diff options
author | Tim Northover <tnorthover@apple.com> | 2023-03-10 17:53:49 +0000 |
---|---|---|
committer | Tim Northover <t.p.northover@gmail.com> | 2023-03-10 18:23:25 +0000 |
commit | 5c18444289f0e618b8491429a34d65577b0d4c32 (patch) | |
tree | 1798f9266f50859dc7b613aca20ecf4c6beab7b1 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | e1462d14b1e4be329a95bdd08181b97a7a3ad6e6 (diff) | |
download | llvm-5c18444289f0e618b8491429a34d65577b0d4c32.zip llvm-5c18444289f0e618b8491429a34d65577b0d4c32.tar.gz llvm-5c18444289f0e618b8491429a34d65577b0d4c32.tar.bz2 |
MachO: support custom section names on global variables
These attributes have been accepted in ELF for a while, and are generated by
Clang in some places, so it makes sense to support them on MachO too.
https://reviews.llvm.org/D143173
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index b78a4d2..5f9e9ea 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1267,6 +1267,20 @@ MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal( StringRef SectionName = GO->getSection(); + const GlobalVariable *GV = dyn_cast<GlobalVariable>(GO); + if (GV && GV->hasImplicitSection()) { + auto Attrs = GV->getAttributes(); + if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) { + SectionName = Attrs.getAttribute("bss-section").getValueAsString(); + } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) { + SectionName = Attrs.getAttribute("rodata-section").getValueAsString(); + } else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) { + SectionName = Attrs.getAttribute("relro-section").getValueAsString(); + } else if (Attrs.hasAttribute("data-section") && Kind.isData()) { + SectionName = Attrs.getAttribute("data-section").getValueAsString(); + } + } + const Function *F = dyn_cast<Function>(GO); if (F && F->hasFnAttribute("implicit-section-name")) { SectionName = F->getFnAttribute("implicit-section-name").getValueAsString(); |