[llvm] r337613 - [COFF] Adjust how we flag weak externals
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 20 13:48:29 PDT 2018
Author: mstorsjo
Date: Fri Jul 20 13:48:29 2018
New Revision: 337613
URL: http://llvm.org/viewvc/llvm-project?rev=337613&view=rev
Log:
[COFF] Adjust how we flag weak externals
This fixes PR36096.
Originally based on a patch by Martell Malone.
Differential Revision: https://reviews.llvm.org/D44357
Added:
llvm/trunk/test/tools/llvm-ar/coff-weak.yaml
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/lib/Object/ArchiveWriter.cpp
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def
llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=337613&r1=337612&r2=337613&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Fri Jul 20 13:48:29 2018
@@ -276,6 +276,7 @@ struct coff_symbol_generic {
};
struct coff_aux_section_definition;
+struct coff_aux_weak_external;
class COFFSymbolRef {
public:
@@ -360,6 +361,13 @@ public:
return getAux<coff_aux_section_definition>();
}
+ const coff_aux_weak_external *getWeakExternal() const {
+ if (!getNumberOfAuxSymbols() ||
+ getStorageClass() != COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL)
+ return nullptr;
+ return getAux<coff_aux_weak_external>();
+ }
+
bool isAbsolute() const {
return getSectionNumber() == -1;
}
Modified: llvm/trunk/lib/Object/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ArchiveWriter.cpp?rev=337613&r1=337612&r2=337613&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp Fri Jul 20 13:48:29 2018
@@ -294,8 +294,7 @@ static bool isArchiveSymbol(const object
return false;
if (!(Symflags & object::SymbolRef::SF_Global))
return false;
- if (Symflags & object::SymbolRef::SF_Undefined &&
- !(Symflags & object::SymbolRef::SF_Indirect))
+ if (Symflags & object::SymbolRef::SF_Undefined)
return false;
return true;
}
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=337613&r1=337612&r2=337613&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Fri Jul 20 13:48:29 2018
@@ -217,10 +217,10 @@ uint32_t COFFObjectFile::getSymbolFlags(
if (Symb.isExternal() || Symb.isWeakExternal())
Result |= SymbolRef::SF_Global;
- if (Symb.isWeakExternal()) {
+ if (const coff_aux_weak_external *AWE = Symb.getWeakExternal()) {
Result |= SymbolRef::SF_Weak;
- // We use indirect to allow the archiver to write weak externs
- Result |= SymbolRef::SF_Indirect;
+ if (AWE->Characteristics != COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS)
+ Result |= SymbolRef::SF_Undefined;
}
if (Symb.getSectionNumber() == COFF::IMAGE_SYM_ABSOLUTE)
@@ -235,7 +235,7 @@ uint32_t COFFObjectFile::getSymbolFlags(
if (Symb.isCommon())
Result |= SymbolRef::SF_Common;
- if (Symb.isAnyUndefined())
+ if (Symb.isUndefined())
Result |= SymbolRef::SF_Undefined;
return Result;
Added: llvm/trunk/test/tools/llvm-ar/coff-weak.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ar/coff-weak.yaml?rev=337613&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ar/coff-weak.yaml (added)
+++ llvm/trunk/test/tools/llvm-ar/coff-weak.yaml Fri Jul 20 13:48:29 2018
@@ -0,0 +1,53 @@
+# RUN: yaml2obj %s -o %t.obj
+#
+# RUN: rm -f %t.ar
+# RUN: llvm-ar crs %t.a %t.obj
+# RUN: llvm-nm -print-armap %t.a | FileCheck %s
+
+# CHECK: Archive map
+# CHECK-NEXT: WeakSearchAlias in coff-weak.yaml.tmp.obj
+# CHECK-EMPTY:
+
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_UNKNOWN
+ Characteristics: [ ]
+sections:
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ SectionData: ''
+symbols:
+ - Name: NormalUndefined
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: WeakSearchAlias
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL
+ WeakExternal:
+ TagIndex: 0
+ Characteristics: IMAGE_WEAK_EXTERN_SEARCH_ALIAS
+ - Name: WeakSearchLibrary
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL
+ WeakExternal:
+ TagIndex: 0
+ Characteristics: IMAGE_WEAK_EXTERN_SEARCH_LIBRARY
+ - Name: WeakSearchNolibrary
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_WEAK_EXTERNAL
+ WeakExternal:
+ TagIndex: 0
+ Characteristics: IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY
+...
Modified: llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def?rev=337613&r1=337612&r2=337613&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def (original)
+++ llvm/trunk/test/tools/llvm-dlltool/coff-decorated.def Fri Jul 20 13:48:29 2018
@@ -22,5 +22,5 @@ StdcallAlias at 4==StdcallFunction at 4
; CHECK: Name type: name
; CHECK: Symbol: __imp_??_7exception@@6B@
; CHECK: Symbol: ??_7exception@@6B@
-; CHECK-NM: w _StdcallAlias at 4
+; CHECK-NM: W _StdcallAlias at 4
; CHECK-NM: U _StdcallFunction at 4
Modified: llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def?rev=337613&r1=337612&r2=337613&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def (original)
+++ llvm/trunk/test/tools/llvm-dlltool/coff-weak-exports.def Fri Jul 20 13:48:29 2018
@@ -15,14 +15,14 @@ ImpLibName2 = Implementation2 == AltTest
ImpLibName3 = kernel32.Sleep
; CHECK: U AltTestFunction
-; CHECK-NEXT: w TestFunction
+; CHECK-NEXT: W TestFunction
; CHECK: U __imp_AltTestFunction
-; CHECK-NEXT: w __imp_TestFunction
+; CHECK-NEXT: W __imp_TestFunction
; CHECK: T ImpLibName
; CHECK-NEXT: T __imp_ImpLibName
; CHECK: U AltTestFunction2
-; CHECK-NEXT: w ImpLibName2
+; CHECK-NEXT: W ImpLibName2
; CHECK: U __imp_AltTestFunction2
-; CHECK-NEXT: w __imp_ImpLibName2
+; CHECK-NEXT: W __imp_ImpLibName2
; CHECK: T ImpLibName3
; CHECK-NEXT: T __imp_ImpLibName3
More information about the llvm-commits
mailing list