[lld] r301013 - COFF: add support for CONSTANT exports
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 11:05:47 PDT 2017
Author: compnerd
Date: Fri Apr 21 13:05:46 2017
New Revision: 301013
URL: http://llvm.org/viewvc/llvm-project?rev=301013&view=rev
Log:
COFF: add support for CONSTANT exports
The CONSTANT export type is marked as obsolete, but link still supports
this. Furthermore, WinObjC uses this for certain exports. Add support
for this export type.
Added:
lld/trunk/test/COFF/Inputs/constant-export.ll
lld/trunk/test/COFF/constant-export.test
lld/trunk/test/COFF/constant-export.yaml
Modified:
lld/trunk/COFF/Config.h
lld/trunk/COFF/DriverUtils.cpp
lld/trunk/COFF/Librarian.cpp
lld/trunk/COFF/ModuleDef.cpp
Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=301013&r1=301012&r2=301013&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Fri Apr 21 13:05:46 2017
@@ -43,6 +43,7 @@ struct Export {
bool Noname = false;
bool Data = false;
bool Private = false;
+ bool Constant = false;
// If an export is a form of /export:foo=dllname.bar, that means
// that foo should be exported as an alias to bar in the DLL.
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=301013&r1=301012&r2=301013&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Fri Apr 21 13:05:46 2017
@@ -479,6 +479,10 @@ Export parseExport(StringRef Arg) {
E.Data = true;
continue;
}
+ if (Tok.equals_lower("constant")) {
+ E.Constant = true;
+ continue;
+ }
if (Tok.equals_lower("private")) {
E.Private = true;
continue;
Modified: lld/trunk/COFF/Librarian.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Librarian.cpp?rev=301013&r1=301012&r2=301013&view=diff
==============================================================================
--- lld/trunk/COFF/Librarian.cpp (original)
+++ lld/trunk/COFF/Librarian.cpp Fri Apr 21 13:05:46 2017
@@ -162,7 +162,7 @@ public:
// Create a short import file which is described in PE/COFF spec 7. Import
// Library Format.
NewArchiveMember createShortImport(StringRef Sym, uint16_t Ordinal,
- ImportNameType NameType, bool isData);
+ ImportType Type, ImportNameType NameType);
};
}
@@ -440,8 +440,8 @@ NewArchiveMember ObjectFactory::createNu
NewArchiveMember ObjectFactory::createShortImport(StringRef Sym,
uint16_t Ordinal,
- ImportNameType NameType,
- bool isData) {
+ ImportType ImportType,
+ ImportNameType NameType) {
size_t ImpSize = DLLName.size() + Sym.size() + 2; // +2 for NULs
size_t Size = sizeof(coff_import_header) + ImpSize;
char *Buf = Alloc.Allocate<char>(Size);
@@ -456,8 +456,7 @@ NewArchiveMember ObjectFactory::createSh
Imp->SizeOfData = ImpSize;
if (Ordinal > 0)
Imp->OrdinalHint = Ordinal;
- Imp->TypeInfo = (isData ? IMPORT_DATA : IMPORT_CODE);
- Imp->TypeInfo |= NameType << 2;
+ Imp->TypeInfo = (NameType << 2) | ImportType;
// Write symbol name and DLL name.
memcpy(P, Sym.data(), Sym.size());
@@ -490,11 +489,18 @@ void lld::coff::writeImportLibrary() {
if (E.Private)
continue;
- ImportNameType Type = getNameType(E.SymbolName, E.Name);
+ ImportType ImportType = IMPORT_CODE;
+ if (E.Data)
+ ImportType = IMPORT_DATA;
+ if (E.Constant)
+ ImportType = IMPORT_CONST;
+
+ ImportNameType NameType = getNameType(E.SymbolName, E.Name);
std::string Name = E.ExtName.empty()
? std::string(E.SymbolName)
: replace(E.SymbolName, E.Name, E.ExtName);
- Members.push_back(OF.createShortImport(Name, E.Ordinal, Type, E.Data));
+ Members.push_back(OF.createShortImport(Name, E.Ordinal, ImportType,
+ NameType));
}
std::pair<StringRef, std::error_code> Result =
Modified: lld/trunk/COFF/ModuleDef.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ModuleDef.cpp?rev=301013&r1=301012&r2=301013&view=diff
==============================================================================
--- lld/trunk/COFF/ModuleDef.cpp (original)
+++ lld/trunk/COFF/ModuleDef.cpp Fri Apr 21 13:05:46 2017
@@ -38,6 +38,7 @@ enum Kind {
Comma,
Equal,
KwBase,
+ KwConstant,
KwData,
KwExports,
KwHeapsize,
@@ -92,6 +93,7 @@ public:
StringRef Word = Buf.substr(0, End);
Kind K = llvm::StringSwitch<Kind>(Word)
.Case("BASE", KwBase)
+ .Case("CONSTANT", KwConstant)
.Case("DATA", KwData)
.Case("EXPORTS", KwExports)
.Case("HEAPSIZE", KwHeapsize)
@@ -227,6 +229,11 @@ private:
E.Data = true;
continue;
}
+ if (Tok.K == KwConstant) {
+ warn("CONSTANT keyword is obsolete; use DATA");
+ E.Constant = true;
+ continue;
+ }
if (Tok.K == KwPrivate) {
E.Private = true;
continue;
Added: lld/trunk/test/COFF/Inputs/constant-export.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/constant-export.ll?rev=301013&view=auto
==============================================================================
--- lld/trunk/test/COFF/Inputs/constant-export.ll (added)
+++ lld/trunk/test/COFF/Inputs/constant-export.ll Fri Apr 21 13:05:46 2017
@@ -0,0 +1,10 @@
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i686-unknown-windows-msvc18.0.0"
+
+ at __CFConstantStringClassReference = common global [32 x i32] zeroinitializer, align 4
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 6, !"Linker Options", !1}
+!1 = !{!2}
+!2 = !{!" -export:___CFConstantStringClassReference,CONSTANT"}
Added: lld/trunk/test/COFF/constant-export.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/constant-export.test?rev=301013&view=auto
==============================================================================
--- lld/trunk/test/COFF/constant-export.test (added)
+++ lld/trunk/test/COFF/constant-export.test Fri Apr 21 13:05:46 2017
@@ -0,0 +1,9 @@
+# RUN: mkdir -p %t
+# RUN: yaml2obj -o %t/constant-export.obj %S/constant-export.yaml
+# RUN: lld-link /machine:x86 /dll /entry:__CFConstantStringClassReference -out:%t/constant-export.dll %t/constant-export.obj
+# RUN: llvm-readobj -coff-exports %t/constant-export.lib | FileCheck %s
+
+# CHECK: Type: const
+# CHECK: Name type: noprefix
+# CHECK: Symbol: __imp____CFConstantStringClassReference
+
Added: lld/trunk/test/COFF/constant-export.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/constant-export.yaml?rev=301013&view=auto
==============================================================================
--- lld/trunk/test/COFF/constant-export.yaml (added)
+++ lld/trunk/test/COFF/constant-export.yaml Fri Apr 21 13:05:46 2017
@@ -0,0 +1,83 @@
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: ''
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: ''
+ - Name: .bss
+ Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: ''
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 1
+ SectionData: 20202D6578706F72743A5F5F5F4346436F6E7374616E74537472696E67436C6173735265666572656E63652C434F4E5354414E54
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 2
+ - Name: .bss
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 3
+ - Name: .drectve
+ Value: 0
+ SectionNumber: 4
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 52
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 1983959296
+ Number: 4
+ - Name: '@feat.00'
+ Value: 1
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: ___CFConstantStringClassReference
+ Value: 128
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
More information about the llvm-commits
mailing list