diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -149,6 +149,7 @@ symbol_list WeakDefaults; bool UseBigObj; + bool KeepTemporarySymbols; bool EmitAddrsigSection = false; MCSectionCOFF *AddrsigSection; @@ -244,6 +245,7 @@ std::unique_ptr MOTW, raw_pwrite_stream &OS) : W(OS, support::little), TargetObjectWriter(std::move(MOTW)) { Header.Machine = TargetObjectWriter->getMachine(); + KeepTemporarySymbols = Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64; } COFFSymbol *WinCOFFObjectWriter::createSymbol(StringRef Name) { @@ -419,8 +421,10 @@ bool IsExternal = MCSym.isExternal() || (!MCSym.getFragment() && !MCSym.isVariable()); - Local->Data.StorageClass = IsExternal ? COFF::IMAGE_SYM_CLASS_EXTERNAL - : COFF::IMAGE_SYM_CLASS_STATIC; + Local->Data.StorageClass = + IsExternal ? COFF::IMAGE_SYM_CLASS_EXTERNAL + : MCSym.isTemporary() ? COFF::IMAGE_SYM_CLASS_LABEL + : COFF::IMAGE_SYM_CLASS_STATIC; } } @@ -691,7 +695,8 @@ defineSection(static_cast(Section)); for (const MCSymbol &Symbol : Asm.symbols()) - if (!Symbol.isTemporary()) + if (!Symbol.isTemporary() || + (KeepTemporarySymbols && !Symbol.getName().empty())) DefineSymbol(Symbol, Asm, Layout); } @@ -769,7 +774,7 @@ Reloc.Data.VirtualAddress = Layout.getFragmentOffset(Fragment); // Turn relocations for temporary symbols into section relocations. - if (A.isTemporary()) { + if (A.isTemporary() && (!KeepTemporarySymbols || A.getName().empty())) { MCSection *TargetSection = &A.getSection(); assert( SectionMap.find(TargetSection) != SectionMap.end() && diff --git a/llvm/test/MC/AArch64/coff-relocations.s b/llvm/test/MC/AArch64/coff-relocations.s --- a/llvm/test/MC/AArch64/coff-relocations.s +++ b/llvm/test/MC/AArch64/coff-relocations.s @@ -2,6 +2,7 @@ // RUN: llvm-readobj -r %t.obj | FileCheck %s // RUN: llvm-objdump -d %t.obj | FileCheck %s --check-prefix=DISASM // RUN: llvm-objdump -s %t.obj | FileCheck %s --check-prefix=DATA +// RUN: llvm-readobj --syms %t.obj | FileCheck %s --check-prefix=SYMBOLS // IMAGE_REL_ARM64_ADDR32 .Linfo_foo: @@ -84,7 +85,7 @@ // CHECK: 0x1C IMAGE_REL_ARM64_PAGEOFFSET_12A foo // CHECK: 0x20 IMAGE_REL_ARM64_PAGEOFFSET_12L foo // CHECK: 0x24 IMAGE_REL_ARM64_PAGEBASE_REL21 bar -// CHECK: 0x28 IMAGE_REL_ARM64_SECREL .text +// CHECK: 0x28 IMAGE_REL_ARM64_SECREL .Linfo_bar // CHECK: 0x2C IMAGE_REL_ARM64_SECTION func // CHECK: 0x30 IMAGE_REL_ARM64_PAGEBASE_REL21 baz // CHECK: 0x34 IMAGE_REL_ARM64_PAGEOFFSET_12A foo @@ -98,9 +99,9 @@ // CHECK: 0x54 IMAGE_REL_ARM64_BRANCH14 target // CHECK: } // CHECK: Section (4) .rdata { -// CHECK: 0x0 IMAGE_REL_ARM64_REL32 .text -// CHECK: 0x4 IMAGE_REL_ARM64_REL32 .text -// CHECK: 0x8 IMAGE_REL_ARM64_REL32 .text +// CHECK: 0x0 IMAGE_REL_ARM64_REL32 .Linfo_bar +// CHECK: 0x4 IMAGE_REL_ARM64_REL32 .Linfo_foo +// CHECK: 0x8 IMAGE_REL_ARM64_REL32 .Linfo_foo // CHECK: } // CHECK: ] @@ -114,4 +115,14 @@ // DISASM: 4c: 20 1a 09 30 adr x0, #74565 // DATA: Contents of section .rdata: -// DATA-NEXT: 0000 30000000 08000000 +// DATA-NEXT: 0000 04000000 08000000 + +// SYMBOLS: Symbol { +// SYMBOLS: Name: .Linfo_foo +// SYMBOLS-NEXT: Value: 0 +// SYMBOLS-NEXT: Section: .text +// SYMBOLS-NEXT: BaseType: Null +// SYMBOLS-NEXT: ComplexType: Null +// SYMBOLS-NEXT: StorageClass: Label +// SYMBOLS-NEXT: AuxSymbolCount: 0 +// SYMBOLS-NEXT: }