diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -786,7 +786,8 @@ void ELFWriter::writeAddrsigSection() { for (const MCSymbol *Sym : OWriter.AddrsigSyms) - encodeULEB128(Sym->getIndex(), W.OS); + if (Sym->getIndex() != 0) + encodeULEB128(Sym->getIndex(), W.OS); } MCSectionELF *ELFWriter::createRelocationSection(MCContext &Ctx, diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -912,7 +912,6 @@ } void MCObjectStreamer::emitAddrsigSym(const MCSymbol *Sym) { - getAssembler().registerSymbol(*Sym); getAssembler().getWriter().addAddrsigSymbol(Sym); } diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -758,6 +758,8 @@ Asm.getContext().getObjectFileInfo()->getAddrSigSection(); unsigned Log2Size = is64Bit() ? 3 : 2; for (const MCSymbol *S : getAddrsigSyms()) { + if (!S->isRegistered()) + continue; MachO::any_relocation_info MRE; MRE.r_word0 = 0; MRE.r_word1 = (Log2Size << 25) | (MachO::GENERIC_RELOC_VANILLA << 28); 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 @@ -1098,6 +1098,8 @@ Frag->setLayoutOrder(0); raw_svector_ostream OS(Frag->getContents()); for (const MCSymbol *S : AddrsigSyms) { + if (!S->isRegistered()) + continue; if (!S->isTemporary()) { encodeULEB128(S->getIndex(), OS); continue; diff --git a/llvm/test/MC/COFF/addrsig.s b/llvm/test/MC/COFF/addrsig.s --- a/llvm/test/MC/COFF/addrsig.s +++ b/llvm/test/MC/COFF/addrsig.s @@ -14,38 +14,53 @@ // CHECK-NEXT: IMAGE_SCN_LNK_REMOVE (0x800) // CHECK-NEXT: ] // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 080A0B02 +// CHECK-NEXT: 0000: 080B0A02 // CHECK-NEXT: ) // CHECK: Symbols [ -// CHECK: Name: .text +// CHECK: Name: +// CHECK-SAME: {{^}} .text // CHECK: AuxSectionDef -// CHECK: Name: .data +// CHECK: Name: +// CHECK-SAME: {{^}} .data // CHECK: AuxSectionDef -// CHECK: Name: .bss +// CHECK: Name: +// CHECK-SAME: {{^}} .bss // CHECK: AuxSectionDef -// CHECK: Name: .llvm_addrsig +// CHECK: Name: +// CHECK-SAME: {{^}} .llvm_addrsig // CHECK: AuxSectionDef -// CHECK: Name: g1 -// CHECK: Name: g2 -// CHECK: Name: g3 -// CHECK: Name: local +// CHECK: Name: +// CHECK-SAME: {{^}} g1 +// CHECK: Name: +// CHECK-SAME: {{^}} g2 +// CHECK: Name: +// CHECK-SAME: {{^}} local +// CHECK: Name: +// CHECK-SAME: {{^}} g3 +// CHECK-NOT: Name: +// CHECK: } // CHECK: Addrsig [ // CHECK-NEXT: Sym: g1 (8) -// CHECK-NEXT: Sym: g3 (10) -// CHECK-NEXT: Sym: local (11) +// CHECK-NEXT: Sym: g3 (11) +// CHECK-NEXT: Sym: local (10) // CHECK-NEXT: Sym: .data (2) // CHECK-NEXT: ] +.globl g1 + .addrsig .addrsig_sym g1 .globl g2 .addrsig_sym g3 .addrsig_sym local .addrsig_sym .Llocal +.addrsig_sym .Lunseen +.addrsig_sym unseen local: +.globl g3 .data .Llocal: diff --git a/llvm/test/MC/ELF/addrsig-error.s b/llvm/test/MC/ELF/addrsig-error.s deleted file mode 100644 --- a/llvm/test/MC/ELF/addrsig-error.s +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s -// CHECK: Undefined temporary symbol - -.addrsig -.addrsig_sym .Lundef diff --git a/llvm/test/MC/ELF/addrsig.s b/llvm/test/MC/ELF/addrsig.s --- a/llvm/test/MC/ELF/addrsig.s +++ b/llvm/test/MC/ELF/addrsig.s @@ -62,6 +62,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: g3 +// CHECK-NOT: Symbol { // CHECK: Addrsig [ // CHECK-NEXT: Sym: g1 (3) @@ -70,6 +71,8 @@ // CHECK-NEXT: Sym: (1) // CHECK-NEXT: ] +.globl g1 + // ASM: .addrsig // ASM-NEXT: .addrsig_sym g1 .addrsig @@ -78,11 +81,17 @@ // ASM: .addrsig_sym g3 // ASM-NEXT: .addrsig_sym local // ASM-NEXT: .addrsig_sym .Llocal +// ASM-NEXT: .addrsig_sym .Lunseen +// ASM-NEXT: .addrsig_sym unseen .addrsig_sym g3 .addrsig_sym local .addrsig_sym .Llocal +.addrsig_sym .Lunseen +.addrsig_sym unseen local: .Llocal: +.globl g3 + // DWO-NOT: .llvm_addrsig diff --git a/llvm/test/MC/MachO/addrsig.s b/llvm/test/MC/MachO/addrsig.s --- a/llvm/test/MC/MachO/addrsig.s +++ b/llvm/test/MC/MachO/addrsig.s @@ -15,10 +15,10 @@ # CHECK: Symbol { # CHECK-NEXT: Name: local # CHECK: Symbol { -# CHECK-NEXT: Name: .Llocal -# CHECK: Symbol { # CHECK-NEXT: Name: ltmp1 # CHECK: Symbol { +# CHECK-NEXT: Name: .Llocal +# CHECK: Symbol { # CHECK-NEXT: Name: g1 # CHECK: Symbol { # CHECK-NEXT: Name: g2 @@ -35,6 +35,8 @@ .addrsig_sym g3 .addrsig_sym local .addrsig_sym .Llocal +.addrsig_sym .Lunseen +.addrsig_sym unseen local: nop