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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212899 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2014-07-13 04:31:19 +00:00
parent 0ed20177c2
commit f803b3d992
3 changed files with 27 additions and 17 deletions

View File

@ -153,7 +153,7 @@ public:
void MakeSymbolReal(COFFSymbol &S, size_t Index); void MakeSymbolReal(COFFSymbol &S, size_t Index);
void MakeSectionReal(COFFSection &S, size_t Number); void MakeSectionReal(COFFSection &S, size_t Number);
bool ExportSymbol(MCSymbolData const &SymbolData, MCAssembler &Asm); bool ExportSymbol(const MCSymbol &Symbol, MCAssembler &Asm);
bool IsPhysicalSection(COFFSection *S); bool IsPhysicalSection(COFFSection *S);
@ -456,10 +456,13 @@ void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData,
// If no storage class was specified in the streamer, define it here. // If no storage class was specified in the streamer, define it here.
if (coff_symbol->Data.StorageClass == 0) { if (coff_symbol->Data.StorageClass == 0) {
bool external = ResSymData.isExternal() || !ResSymData.Fragment; bool IsExternal =
ResSymData.isExternal() ||
(!ResSymData.getFragment() && !ResSymData.getSymbol().isVariable());
coff_symbol->Data.StorageClass = coff_symbol->Data.StorageClass = IsExternal
external ? COFF::IMAGE_SYM_CLASS_EXTERNAL : COFF::IMAGE_SYM_CLASS_STATIC; ? COFF::IMAGE_SYM_CLASS_EXTERNAL
: COFF::IMAGE_SYM_CLASS_STATIC;
} }
if (!Base) { if (!Base) {
@ -546,16 +549,24 @@ void WinCOFFObjectWriter::MakeSymbolReal(COFFSymbol &S, size_t Index) {
S.Index = Index; S.Index = Index;
} }
bool WinCOFFObjectWriter::ExportSymbol(MCSymbolData const &SymbolData, bool WinCOFFObjectWriter::ExportSymbol(const MCSymbol &Symbol,
MCAssembler &Asm) { MCAssembler &Asm) {
// This doesn't seem to be right. Strings referred to from the .data section // This doesn't seem to be right. Strings referred to from the .data section
// need symbols so they can be linked to code in the .text section right? // need symbols so they can be linked to code in the .text section right?
// return Asm.isSymbolLinkerVisible(SymbolData.getSymbol()); // return Asm.isSymbolLinkerVisible(Symbol);
// Non-temporary labels should always be visible to the linker.
if (!Symbol.isTemporary())
return true;
// Absolute temporary labels are never visible.
if (!Symbol.isInSection())
return false;
// For now, all non-variable symbols are exported, // For now, all non-variable symbols are exported,
// the linker will sort the rest out for us. // the linker will sort the rest out for us.
return SymbolData.isExternal() || !SymbolData.getSymbol().isVariable(); return !Symbol.isVariable();
} }
bool WinCOFFObjectWriter::IsPhysicalSection(COFFSection *S) { bool WinCOFFObjectWriter::IsPhysicalSection(COFFSection *S) {
@ -689,7 +700,7 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
DefineSection(Section); DefineSection(Section);
for (MCSymbolData &SD : Asm.symbols()) for (MCSymbolData &SD : Asm.symbols())
if (ExportSymbol(SD, Asm)) if (ExportSymbol(SD.getSymbol(), Asm))
DefineSymbol(SD, Asm, Layout); DefineSymbol(SD, Asm, Layout);
} }

View File

@ -46,7 +46,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: AuxSymbolCount: 0 // CHECK-NEXT: AuxSymbolCount: 0
// CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: Symbol { // CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: global_aliased_to_external // CHECK: Name: global_aliased_to_external
// CHECK-NEXT: Value: 0 // CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0) // CHECK-NEXT: Section: (0)
// CHECK-NEXT: BaseType: Null (0x0) // CHECK-NEXT: BaseType: Null (0x0)
@ -90,7 +90,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: StorageClass: WeakExternal (0x69) // CHECK-NEXT: StorageClass: WeakExternal (0x69)
// CHECK-NEXT: AuxSymbolCount: 1 // CHECK-NEXT: AuxSymbolCount: 1
// CHECK-NEXT: AuxWeakExternal { // CHECK-NEXT: AuxWeakExternal {
// CHECK-NEXT: Linked: external2 (13) // CHECK-NEXT: Linked: external2
// CHECK-NEXT: Search: Library (0x2) // CHECK-NEXT: Search: Library (0x2)
// CHECK-NEXT: Unused: (00 00 00 00 00 00 00 00 00 00) // CHECK-NEXT: Unused: (00 00 00 00 00 00 00 00 00 00)
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -1,12 +1,11 @@
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-nm - | FileCheck %s // RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-nm - | FileCheck %s --check-prefix=GLOBAL
// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-nm - | FileCheck %s --check-prefix=LOCAL
not_global = 123 not_global = 123
global = 456 global = 456
.globl global .globl global
.Llocal = 789 Llocal = 789
// CHECK-NOT: not_global // LOCAL-NOT: local
// CHECK-NOT: Llocal // GLOBAL: A global
// CHECK: global // GLOBAL: a not_global
// CHECK-NOT: not_global
// CHECK-NOT: Llocal