diff options
| author | Steven Wu <stevenwu@apple.com> | 2018-04-10 20:16:35 +0000 |
|---|---|---|
| committer | Steven Wu <stevenwu@apple.com> | 2018-04-10 20:16:35 +0000 |
| commit | d0804aa6dc476f75017a74d5fd77e737efe9a9ea (patch) | |
| tree | 63f04a66107c24bc5694b7164efcccac0e6dcb30 /llvm | |
| parent | c0f879bcecd4058732aad6c1e113adf78990f5a3 (diff) | |
| download | bcm5719-llvm-d0804aa6dc476f75017a74d5fd77e737efe9a9ea.tar.gz bcm5719-llvm-d0804aa6dc476f75017a74d5fd77e737efe9a9ea.zip | |
[MachO] Emit Weak ReadOnlyWithRel to ConstDataSection
Summary:
Darwin dynamic linker can handle weak symbols in ConstDataSection.
ReadonReadOnlyWithRel symbols should be emitted in ConstDataSection
instead of normal DataSection.
rdar://problem/39298457
Reviewers: dexonsmith, kledzik
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D45472
llvm-svn: 329752
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/MC/MCObjectFileInfo.h | 4 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/MC/MCObjectFileInfo.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/global-sections.ll | 5 |
4 files changed, 17 insertions, 3 deletions
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h index af86cb7cf6b..d50c052a99a 100644 --- a/llvm/include/llvm/MC/MCObjectFileInfo.h +++ b/llvm/include/llvm/MC/MCObjectFileInfo.h @@ -183,6 +183,7 @@ protected: MCSection *ConstTextCoalSection; MCSection *ConstDataSection; MCSection *DataCoalSection; + MCSection *ConstDataCoalSection; MCSection *DataCommonSection; MCSection *DataBSSSection; MCSection *FourByteConstantSection; @@ -328,6 +329,9 @@ public: } const MCSection *getConstDataSection() const { return ConstDataSection; } const MCSection *getDataCoalSection() const { return DataCoalSection; } + const MCSection *getConstDataCoalSection() const { + return ConstDataCoalSection; + } const MCSection *getDataCommonSection() const { return DataCommonSection; } MCSection *getDataBSSSection() const { return DataBSSSection; } const MCSection *getFourByteConstantSection() const { diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index dc3efe1d4bc..a4a54e1fb24 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -744,6 +744,8 @@ MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal( if (GO->isWeakForLinker()) { if (Kind.isReadOnly()) return ConstTextCoalSection; + if (Kind.isReadOnlyWithRel()) + return ConstDataCoalSection; return DataCoalSection; } diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp index b154c98cf72..5b3636153d6 100644 --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -135,6 +135,10 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { // "__DATA/__datacoal_nt" => section "__DATA/__data" Triple::ArchType ArchTy = T.getArch(); + ConstDataSection // .const_data + = Ctx->getMachOSection("__DATA", "__const", 0, + SectionKind::getReadOnlyWithRel()); + if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) { TextCoalSection = Ctx->getMachOSection("__TEXT", "__textcoal_nt", @@ -147,15 +151,14 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { SectionKind::getReadOnly()); DataCoalSection = Ctx->getMachOSection( "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData()); + ConstDataCoalSection = DataCoalSection; } else { TextCoalSection = TextSection; ConstTextCoalSection = ReadOnlySection; DataCoalSection = DataSection; + ConstDataCoalSection = ConstDataSection; } - ConstDataSection // .const_data - = Ctx->getMachOSection("__DATA", "__const", 0, - SectionKind::getReadOnlyWithRel()); DataCommonSection = Ctx->getMachOSection("__DATA","__common", MachO::S_ZEROFILL, diff --git a/llvm/test/CodeGen/X86/global-sections.ll b/llvm/test/CodeGen/X86/global-sections.ll index ea6df468ceb..5f8cd90c8b5 100644 --- a/llvm/test/CodeGen/X86/global-sections.ll +++ b/llvm/test/CodeGen/X86/global-sections.ll @@ -329,3 +329,8 @@ bb7: ; WIN32-SECTIONS: .section .bss,"bw",one_only,_G17 ; WIN32-SECTIONS: _G17: ; WIN32-SECTIONS:.byte 0 + +; check weak ReadOnlyWithRel globals. +@G18 = linkonce_odr unnamed_addr constant i64* @G15 +; DARWIN64: .section __DATA,__const +; DARWIN64: _G18: |

