[llvm] r339942 - [MC] Improve COFF associative section lookup
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 16 14:34:41 PDT 2018
Author: rnk
Date: Thu Aug 16 14:34:41 2018
New Revision: 339942
URL: http://llvm.org/viewvc/llvm-project?rev=339942&view=rev
Log:
[MC] Improve COFF associative section lookup
Handle the case when the symbol is private. Private symbols are not in
the COFF object file symbol table, so they aren't inserted into
SymbolMap. We can't look up the section of the symbol that way. Instead,
get the MCSection from the MCSymbol and map that to the object file
section.
Print a better error message when the symbol has no section, like when
the symbol is undefined.
Fixes PR38607
Added:
llvm/trunk/test/MC/COFF/assoc-private.s
llvm/trunk/test/MC/COFF/assoc-undef.s
Modified:
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/test/MC/COFF/section-comdat.s
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=339942&r1=339941&r2=339942&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu Aug 16 14:34:41 2018
@@ -1020,22 +1020,28 @@ uint64_t WinCOFFObjectWriter::writeObjec
continue;
const MCSectionCOFF &MCSec = *Section->MCSection;
+ const MCSymbol *AssocMCSym = MCSec.getCOMDATSymbol();
+ assert(AssocMCSym);
- const MCSymbol *COMDAT = MCSec.getCOMDATSymbol();
- assert(COMDAT);
- COFFSymbol *COMDATSymbol = GetOrCreateCOFFSymbol(COMDAT);
- assert(COMDATSymbol);
- COFFSection *Assoc = COMDATSymbol->Section;
- if (!Assoc)
- report_fatal_error(
- Twine("Missing associated COMDAT section for section ") +
- MCSec.getSectionName());
+ // It's an error to try to associate with an undefined symbol or a symbol
+ // without a section.
+ if (!AssocMCSym->isInSection()) {
+ Asm.getContext().reportError(
+ SMLoc(), Twine("cannot make section ") + MCSec.getSectionName() +
+ Twine(" associative with sectionless symbol ") +
+ AssocMCSym->getName());
+ continue;
+ }
+
+ const auto *AssocMCSec = cast<MCSectionCOFF>(&AssocMCSym->getSection());
+ assert(SectionMap.count(AssocMCSec));
+ COFFSection *AssocSec = SectionMap[AssocMCSec];
// Skip this section if the associated section is unused.
- if (Assoc->Number == -1)
+ if (AssocSec->Number == -1)
continue;
- Section->Symbol->Aux[0].Aux.SectionDefinition.Number = Assoc->Number;
+ Section->Symbol->Aux[0].Aux.SectionDefinition.Number = AssocSec->Number;
}
assignFileOffsets(Asm, Layout);
Added: llvm/trunk/test/MC/COFF/assoc-private.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/assoc-private.s?rev=339942&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/assoc-private.s (added)
+++ llvm/trunk/test/MC/COFF/assoc-private.s Thu Aug 16 14:34:41 2018
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -triple x86_64-pc-win32 -filetype=obj %s | llvm-objdump - -h -t | FileCheck %s
+
+# PR38607: We assemble this, and make .CRT$XCU comdat with .rdata even though
+# .rdata isn't comdat. It's not clear what the semantics are, but we assemble
+# it anyway.
+
+# CHECK: Sections:
+# CHECK: Idx Name Size Address Type
+# CHECK: 3 .rdata 00000004 0000000000000000 DATA
+# CHECK: 4 .CRT$XCU 00000008 0000000000000000 DATA
+# CHECK: SYMBOL TABLE:
+# CHECK: [ 6](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .rdata
+# CHECK: AUX scnlen 0x4 nreloc 0 nlnno 0 checksum 0x0 assoc 4 comdat 0
+# CHECK: [ 8](sec 5)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .CRT$XCU
+# CHECK: AUX scnlen 0x8 nreloc 1 nlnno 0 checksum 0x0 assoc 4 comdat 5
+# CHECK: [10](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 register_x
+
+ .section .rdata,"dr"
+ .p2align 2 # @x
+.Lprivate:
+ .long 0 # 0x0
+
+ .section .CRT$XCU,"dr",associative,.Lprivate
+ .p2align 3
+ .quad register_x
+
Added: llvm/trunk/test/MC/COFF/assoc-undef.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/assoc-undef.s?rev=339942&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/assoc-undef.s (added)
+++ llvm/trunk/test/MC/COFF/assoc-undef.s Thu Aug 16 14:34:41 2018
@@ -0,0 +1,8 @@
+# RUN: not llvm-mc %s -filetype=obj -triple=x86_64-windows-msvc -o /dev/null 2>&1 | FileCheck %s
+
+# CHECK: cannot make section assocSec associative with sectionless symbol undef
+
+ .section assocSec,"dr",associative,undef
+ .p2align 3
+ .quad my_initializer
+
Modified: llvm/trunk/test/MC/COFF/section-comdat.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/section-comdat.s?rev=339942&r1=339941&r2=339942&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/section-comdat.s (original)
+++ llvm/trunk/test/MC/COFF/section-comdat.s Thu Aug 16 14:34:41 2018
@@ -2,6 +2,8 @@
// RUN: llvm-mc -triple x86_64-pc-win32 -filetype=obj %s | llvm-readobj -s -t | FileCheck %s
.section assocSec, "dr", discard, "assocSym"
+.global assocSym
+assocSym:
.long 1
.section secName, "dr", discard, "Symbol1"
More information about the llvm-commits
mailing list