From d3a951026462713a377c0fe616bf512de59a56bc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 7 Aug 2013 23:42:09 +0000 Subject: Reapply r185872 now that the address sanitizer has been changed to support this. Original commit message: Stop emitting weak symbols into the "coal" sections. The Mach-O linker has been able to support the weak-def bit on any symbol for quite a while now. The compiler however continued to place these symbols into a "coal" section, which required the linker to map them back to the base section name. Replace the sections like this: __TEXT/__textcoal_nt instead use __TEXT/__text __TEXT/__const_coal instead use __TEXT/__const __DATA/__datacoal_nt instead use __DATA/__data git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187939 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 07cf871..7d9382e 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -524,14 +524,14 @@ const MCSection *TargetLoweringObjectFileMachO:: SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const { if (Kind.isText()) - return GV->isWeakForLinker() ? TextCoalSection : TextSection; - - // If this is weak/linkonce, put this in a coalescable section, either in text - // or data depending on if it is writable. + return TextSection; + + // If this is weak/linkonce, put this in a read only or data section depending + // on whether or not it's writable. if (GV->isWeakForLinker()) { if (Kind.isReadOnly()) - return ConstTextCoalSection; - return DataCoalSection; + return ReadOnlySection; + return DataSection; } // FIXME: Alignment check should be handled by section classifier. -- cgit v1.1 From 9706d43b56e16eb3029314e02c499305284e99f1 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 8 Aug 2013 01:50:52 +0000 Subject: Revert "coff also doesn't have a ReadOnlySection yet, (!)" This reverts commit r77814. We were sticking global constants in the .data section instead of in the .rdata section when emitting for COFF. This fixes PR16831. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187956 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 7d9382e..cf70ad6 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -776,6 +776,9 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, if (Kind.isThreadLocal()) return getTLSDataSection(); + if (Kind.isReadOnly() && ReadOnlySection != 0) + return ReadOnlySection; + return getDataSection(); } -- cgit v1.1 From 9b19dfc2e003e33892be2d80ad535d18f24c53d9 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Thu, 8 Aug 2013 21:04:16 +0000 Subject: Revert "Reapply r185872 now that the address sanitizer has been changed to support this." This reverts commit r187939. It broke an O0 build of a spec benchmark. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188012 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index cf70ad6..ea0d62e 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -524,14 +524,14 @@ const MCSection *TargetLoweringObjectFileMachO:: SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const { if (Kind.isText()) - return TextSection; - - // If this is weak/linkonce, put this in a read only or data section depending - // on whether or not it's writable. + return GV->isWeakForLinker() ? TextCoalSection : TextSection; + + // If this is weak/linkonce, put this in a coalescable section, either in text + // or data depending on if it is writable. if (GV->isWeakForLinker()) { if (Kind.isReadOnly()) - return ReadOnlySection; - return DataSection; + return ConstTextCoalSection; + return DataCoalSection; } // FIXME: Alignment check should be handled by section classifier. -- cgit v1.1 From 6aa9315353574c000c5f2aa0edd34067e94b8c79 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 13 Aug 2013 01:23:53 +0000 Subject: [-cxx-abi microsoft] Stick zero initialized symbols into the .bss section for COFF Summary: We need to do two things: - Initialize BSSSection in MCObjectFileInfo::InitCOFFMCObjectFileInfo - Teach TargetLoweringObjectFileCOFF::SelectSectionForGlobal what to do with it This fixes PR16861. Reviewers: rnk Reviewed By: rnk CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1361 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188244 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index ea0d62e..085e8f4 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -771,15 +771,18 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, } if (Kind.isText()) - return getTextSection(); + return TextSection; if (Kind.isThreadLocal()) - return getTLSDataSection(); + return TLSDataSection; - if (Kind.isReadOnly() && ReadOnlySection != 0) + if (Kind.isReadOnly()) return ReadOnlySection; - return getDataSection(); + if (Kind.isBSS()) + return BSSSection; + + return DataSection; } void TargetLoweringObjectFileCOFF:: -- cgit v1.1 From 93cf0939f95b3d580d9c05375a7c84164e1ba72e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 29 Oct 2013 17:28:26 +0000 Subject: Move getSymbol to TargetLoweringObjectFile. This allows constructing a Mangler with just a TargetMachine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193630 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 085e8f4..5d16f04 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -52,10 +52,10 @@ TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV, default: report_fatal_error("We do not support this DWARF encoding yet!"); case dwarf::DW_EH_PE_absptr: - return Mang->getSymbol(GV); + return getSymbol(*Mang, GV); case dwarf::DW_EH_PE_pcrel: { return getContext().GetOrCreateSymbol(StringRef("DW.ref.") + - Mang->getSymbol(GV)->getName()); + getSymbol(*Mang, GV)->getName()); } } } @@ -104,7 +104,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym); if (StubSym.getPointer() == 0) { - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); } @@ -252,7 +252,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Prefix = getSectionPrefixForGlobal(Kind); SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); Name.append(Sym->getName().begin(), Sym->getName().end()); StringRef Group = ""; unsigned Flags = getELFSectionFlags(Kind); @@ -613,7 +613,7 @@ shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const { // FIXME: ObjC metadata is currently emitted as internal symbols that have // \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and // this horrible hack can go away. - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l') return false; } @@ -642,7 +642,7 @@ getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang, GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) : MachOMMI.getGVStubEntry(SSym); if (StubSym.getPointer() == 0) { - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); } @@ -671,7 +671,7 @@ getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang, MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); if (StubSym.getPointer() == 0) { - MCSymbol *Sym = Mang->getSymbol(GV); + MCSymbol *Sym = getSymbol(*Mang, GV); StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); } -- cgit v1.1 From fe128c6ac8a6ae6aa85f0168f99d9c28de010fd8 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sun, 17 Nov 2013 10:53:13 +0000 Subject: Revert "Micro-optimization" This reverts commit f1d9fe9d04ce93f6d5dcebbd2cb6a07414d7a029. This was causing PR17964. We need to use thread data before regular data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194960 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 5d16f04..66ba3ec 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -523,6 +523,11 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, const MCSection *TargetLoweringObjectFileMachO:: SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const { + + // Handle thread local data. + if (Kind.isThreadBSS()) return TLSBSSSection; + if (Kind.isThreadData()) return TLSDataSection; + if (Kind.isText()) return GV->isWeakForLinker() ? TextCoalSection : TextSection; @@ -575,10 +580,6 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, if (Kind.isBSSLocal()) return DataBSSSection; - // Handle thread local data. - if (Kind.isThreadBSS()) return TLSBSSSection; - if (Kind.isThreadData()) return TLSDataSection; - // Otherwise, just drop the variable in the normal data section. return DataSection; } -- cgit v1.1 From 0ae07098f7d2ad5a1868d448d0b1b4eef2a3b091 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 27 Nov 2013 06:44:18 +0000 Subject: Merging r195148: ------------------------------------------------------------------------ r195148 | rafael | 2013-11-19 11:52:52 -0800 (Tue, 19 Nov 2013) | 15 lines Support multiple COFF sections with the same name but different COMDAT. This is the first step to fix pr17918. It extends the .section directive a bit, inspired by what the ELF one looks like. The problem with using linkonce is that given .section foo .linkonce.... .section foo .linkonce we would already have switched sections when getting to .linkonce. The cleanest solution seems to be to add the comdat information in the .section itself. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195822 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 66ba3ec..59d7b57 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -733,6 +733,7 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, return getContext().getCOFFSection(Name, Characteristics, Kind, + "", Selection); } @@ -768,7 +769,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; return getContext().getCOFFSection(Name.str(), Characteristics, - Kind, COFF::IMAGE_COMDAT_SELECT_ANY); + Kind, "", COFF::IMAGE_COMDAT_SELECT_ANY); } if (Kind.isText()) -- cgit v1.1 From 38af06736e6d46ef3d417e40b9843ca1658fc8e7 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 27 Nov 2013 06:44:45 +0000 Subject: Merging r195798: ------------------------------------------------------------------------ r195798 | rafael | 2013-11-26 17:18:37 -0800 (Tue, 26 Nov 2013) | 9 lines Use simple section names for COMDAT sections on COFF. With this patch we use simple names for COMDAT sections (like .text or .bss). This matches the MSVC behavior. When merging it is the COMDAT symbol that is used to decide if two sections should be merged, so there is no point in building a fancy name. This survived a bootstrap on mingw32. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195823 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 38 +++++++++++++--------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 59d7b57..229ccfa 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -723,33 +723,31 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const { int Selection = 0; unsigned Characteristics = getCOFFSectionFlags(Kind); - SmallString<128> Name(GV->getSection().c_str()); + StringRef Name = GV->getSection(); + StringRef COMDATSymName = ""; if (GV->isWeakForLinker()) { Selection = COFF::IMAGE_COMDAT_SELECT_ANY; Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; - Name.append("$"); - Mang->getNameWithPrefix(Name, GV, false, false); + MCSymbol *Sym = getSymbol(*Mang, GV); + COMDATSymName = Sym->getName(); } return getContext().getCOFFSection(Name, Characteristics, Kind, - "", + COMDATSymName, Selection); } -static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { +static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) { if (Kind.isText()) - return ".text$"; + return ".text"; if (Kind.isBSS ()) - return ".bss$"; - if (Kind.isThreadLocal()) { - // 'LLVM' is just an arbitary string to ensure that the section name gets - // sorted in between '.tls$AAA' and '.tls$ZZZ' by the linker. - return ".tls$LLVM"; - } + return ".bss"; + if (Kind.isThreadLocal()) + return ".tls"; if (Kind.isWriteable()) - return ".data$"; - return ".rdata$"; + return ".data"; + return ".rdata"; } @@ -760,16 +758,14 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, // If this global is linkonce/weak and the target handles this by emitting it // into a 'uniqued' section name, create and return the section now. if (GV->isWeakForLinker()) { - const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); - SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); - Mang->getNameWithPrefix(Name, GV, false, false); - + const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); unsigned Characteristics = getCOFFSectionFlags(Kind); Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; - - return getContext().getCOFFSection(Name.str(), Characteristics, - Kind, "", COFF::IMAGE_COMDAT_SELECT_ANY); + MCSymbol *Sym = getSymbol(*Mang, GV); + return getContext().getCOFFSection(Name, Characteristics, + Kind, Sym->getName(), + COFF::IMAGE_COMDAT_SELECT_ANY); } if (Kind.isText()) -- cgit v1.1 From d0cf77ad590633c0e10336e4c59b509140328042 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sun, 1 Dec 2013 04:40:32 +0000 Subject: --- Reverse-merging r195823 into '.': U lib/MC/MCSectionCOFF.cpp U lib/CodeGen/TargetLoweringObjectFileImpl.cpp U test/MC/COFF/weak-symbol.ll U test/MC/COFF/tricky-names.ll G . --- Recording mergeinfo for reverse merge of r195823 into '.': G . git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@196036 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 38 +++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 229ccfa..59d7b57 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -723,31 +723,33 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const { int Selection = 0; unsigned Characteristics = getCOFFSectionFlags(Kind); - StringRef Name = GV->getSection(); - StringRef COMDATSymName = ""; + SmallString<128> Name(GV->getSection().c_str()); if (GV->isWeakForLinker()) { Selection = COFF::IMAGE_COMDAT_SELECT_ANY; Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; - MCSymbol *Sym = getSymbol(*Mang, GV); - COMDATSymName = Sym->getName(); + Name.append("$"); + Mang->getNameWithPrefix(Name, GV, false, false); } return getContext().getCOFFSection(Name, Characteristics, Kind, - COMDATSymName, + "", Selection); } -static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) { +static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) { if (Kind.isText()) - return ".text"; + return ".text$"; if (Kind.isBSS ()) - return ".bss"; - if (Kind.isThreadLocal()) - return ".tls"; + return ".bss$"; + if (Kind.isThreadLocal()) { + // 'LLVM' is just an arbitary string to ensure that the section name gets + // sorted in between '.tls$AAA' and '.tls$ZZZ' by the linker. + return ".tls$LLVM"; + } if (Kind.isWriteable()) - return ".data"; - return ".rdata"; + return ".data$"; + return ".rdata$"; } @@ -758,14 +760,16 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, // If this global is linkonce/weak and the target handles this by emitting it // into a 'uniqued' section name, create and return the section now. if (GV->isWeakForLinker()) { - const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); + const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind); + SmallString<128> Name(Prefix, Prefix+strlen(Prefix)); + Mang->getNameWithPrefix(Name, GV, false, false); + unsigned Characteristics = getCOFFSectionFlags(Kind); Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; - MCSymbol *Sym = getSymbol(*Mang, GV); - return getContext().getCOFFSection(Name, Characteristics, - Kind, Sym->getName(), - COFF::IMAGE_COMDAT_SELECT_ANY); + + return getContext().getCOFFSection(Name.str(), Characteristics, + Kind, "", COFF::IMAGE_COMDAT_SELECT_ANY); } if (Kind.isText()) -- cgit v1.1