Skip to content

Commit 299674e

Browse files
committed
MC: Let non-temporary COFF aliases be in symtab
MC was aping a binutils bug where aliases would default their linkage to private instead of internal. I've sent a patch to the binutils maintainers and they've recently applied it to the GNU assembler sources. This fixes PR20152. Differential Revision: http://reviews.llvm.org/D4395 llvm-svn: 212899
1 parent c3f6a7e commit 299674e

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class WinCOFFObjectWriter : public MCObjectWriter {
153153
void MakeSymbolReal(COFFSymbol &S, size_t Index);
154154
void MakeSectionReal(COFFSection &S, size_t Number);
155155

156-
bool ExportSymbol(MCSymbolData const &SymbolData, MCAssembler &Asm);
156+
bool ExportSymbol(const MCSymbol &Symbol, MCAssembler &Asm);
157157

158158
bool IsPhysicalSection(COFFSection *S);
159159

@@ -456,10 +456,13 @@ void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData,
456456

457457
// If no storage class was specified in the streamer, define it here.
458458
if (coff_symbol->Data.StorageClass == 0) {
459-
bool external = ResSymData.isExternal() || !ResSymData.Fragment;
459+
bool IsExternal =
460+
ResSymData.isExternal() ||
461+
(!ResSymData.getFragment() && !ResSymData.getSymbol().isVariable());
460462

461-
coff_symbol->Data.StorageClass =
462-
external ? COFF::IMAGE_SYM_CLASS_EXTERNAL : COFF::IMAGE_SYM_CLASS_STATIC;
463+
coff_symbol->Data.StorageClass = IsExternal
464+
? COFF::IMAGE_SYM_CLASS_EXTERNAL
465+
: COFF::IMAGE_SYM_CLASS_STATIC;
463466
}
464467

465468
if (!Base) {
@@ -546,16 +549,24 @@ void WinCOFFObjectWriter::MakeSymbolReal(COFFSymbol &S, size_t Index) {
546549
S.Index = Index;
547550
}
548551

549-
bool WinCOFFObjectWriter::ExportSymbol(MCSymbolData const &SymbolData,
552+
bool WinCOFFObjectWriter::ExportSymbol(const MCSymbol &Symbol,
550553
MCAssembler &Asm) {
551554
// This doesn't seem to be right. Strings referred to from the .data section
552555
// need symbols so they can be linked to code in the .text section right?
553556

554-
// return Asm.isSymbolLinkerVisible(SymbolData.getSymbol());
557+
// return Asm.isSymbolLinkerVisible(Symbol);
558+
559+
// Non-temporary labels should always be visible to the linker.
560+
if (!Symbol.isTemporary())
561+
return true;
562+
563+
// Absolute temporary labels are never visible.
564+
if (!Symbol.isInSection())
565+
return false;
555566

556567
// For now, all non-variable symbols are exported,
557568
// the linker will sort the rest out for us.
558-
return SymbolData.isExternal() || !SymbolData.getSymbol().isVariable();
569+
return !Symbol.isVariable();
559570
}
560571

561572
bool WinCOFFObjectWriter::IsPhysicalSection(COFFSection *S) {
@@ -689,7 +700,7 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
689700
DefineSection(Section);
690701

691702
for (MCSymbolData &SD : Asm.symbols())
692-
if (ExportSymbol(SD, Asm))
703+
if (ExportSymbol(SD.getSymbol(), Asm))
693704
DefineSymbol(SD, Asm, Layout);
694705
}
695706

llvm/test/MC/COFF/alias.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ weak_aliased_to_external = external2
4646
// CHECK-NEXT: AuxSymbolCount: 0
4747
// CHECK-NEXT: }
4848
// CHECK-NEXT: Symbol {
49-
// CHECK-NEXT: Name: global_aliased_to_external
49+
// CHECK: Name: global_aliased_to_external
5050
// CHECK-NEXT: Value: 0
5151
// CHECK-NEXT: Section: (0)
5252
// CHECK-NEXT: BaseType: Null (0x0)
@@ -90,7 +90,7 @@ weak_aliased_to_external = external2
9090
// CHECK-NEXT: StorageClass: WeakExternal (0x69)
9191
// CHECK-NEXT: AuxSymbolCount: 1
9292
// CHECK-NEXT: AuxWeakExternal {
93-
// CHECK-NEXT: Linked: external2 (13)
93+
// CHECK-NEXT: Linked: external2
9494
// CHECK-NEXT: Search: Library (0x2)
9595
// CHECK-NEXT: Unused: (00 00 00 00 00 00 00 00 00 00)
9696
// CHECK-NEXT: }

llvm/test/MC/COFF/lset0.s

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-nm - | FileCheck %s
1+
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-nm - | FileCheck %s --check-prefix=GLOBAL
2+
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-nm - | FileCheck %s --check-prefix=LOCAL
23

34
not_global = 123
45
global = 456
56
.globl global
6-
.Llocal = 789
7+
Llocal = 789
78

8-
// CHECK-NOT: not_global
9-
// CHECK-NOT: Llocal
10-
// CHECK: global
11-
// CHECK-NOT: not_global
12-
// CHECK-NOT: Llocal
9+
// LOCAL-NOT: local
10+
// GLOBAL: A global
11+
// GLOBAL: a not_global

0 commit comments

Comments
 (0)