Skip to content

Commit

Permalink
[llvm-lib] [Object] Use ECSYMBOLS section for ARM64EC importlib symbo…
Browse files Browse the repository at this point in the history
…ls. (#68328)
  • Loading branch information
cjacek committed Oct 12, 2023
1 parent 6cf41ad commit bf0534e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions llvm/include/llvm/Object/COFFImportFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class COFFImportFile : public SymbolicFile {
Data.getBufferStart());
}

uint16_t getMachine() const { return getCOFFImportHeader()->Machine; }

private:
bool isData() const {
return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA;
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Object/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/Error.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Object/MachO.h"
Expand Down Expand Up @@ -659,6 +660,10 @@ static bool isECObject(object::SymbolicFile &Obj) {
return cast<llvm::object::COFFObjectFile>(&Obj)->getMachine() !=
COFF::IMAGE_FILE_MACHINE_ARM64;

if (Obj.isCOFFImportFile())
return cast<llvm::object::COFFImportFile>(&Obj)->getMachine() !=
COFF::IMAGE_FILE_MACHINE_ARM64;

if (Obj.isIR()) {
Expected<std::string> TripleStr =
getBitcodeTargetTriple(Obj.getMemoryBufferRef());
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Object/COFFImportFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,

return writeArchive(Path, Members, SymtabWritingMode::NormalSymtab,
MinGW ? object::Archive::K_GNU : object::Archive::K_COFF,
/*Deterministic*/ true, /*Thin*/ false);
/*Deterministic*/ true, /*Thin*/ false,
/*OldArchiveBuf*/ nullptr, isArm64EC(Machine));
}

} // namespace object
Expand Down
54 changes: 54 additions & 0 deletions llvm/test/tools/llvm-lib/arm64ec-implib.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Test creating ARM64EC importlib.

RUN: split-file %s %t.dir && cd %t.dir
RUN: llvm-lib -machine:arm64ec -def:test.def -out:test.lib

RUN: llvm-nm --print-armap test.lib | FileCheck -check-prefix=ARMAP %s

ARMAP: Archive EC map
ARMAP-NEXT: __IMPORT_DESCRIPTOR_test in test.dll
ARMAP-NEXT: __NULL_IMPORT_DESCRIPTOR in test.dll
ARMAP-NEXT: __imp_dataexp in test.dll
ARMAP-NEXT: __imp_funcexp in test.dll
ARMAP-NEXT: funcexp in test.dll
ARMAP-NEXT: test_NULL_THUNK_DATA in test.dll

RUN: llvm-readobj test.lib | FileCheck -check-prefix=READOBJ %s

READOBJ: File: test.lib(test.dll)
READOBJ-NEXT: Format: COFF-ARM64EC
READOBJ-NEXT: Arch: aarch64
READOBJ-NEXT: AddressSize: 64bit
READOBJ-EMPTY:
READOBJ-NEXT: File: test.lib(test.dll)
READOBJ-NEXT: Format: COFF-ARM64EC
READOBJ-NEXT: Arch: aarch64
READOBJ-NEXT: AddressSize: 64bit
READOBJ-EMPTY:
READOBJ-NEXT: File: test.lib(test.dll)
READOBJ-NEXT: Format: COFF-ARM64
READOBJ-NEXT: Arch: aarch64
READOBJ-NEXT: AddressSize: 64bit
READOBJ-EMPTY:
READOBJ-NEXT: File: test.dll
READOBJ-NEXT: Format: COFF-import-file
READOBJ-NEXT: Type: code
READOBJ-NEXT: Name type: name
READOBJ-NEXT: Symbol: __imp_funcexp
READOBJ-NEXT: Symbol: funcexp
READOBJ-EMPTY:
READOBJ-NEXT: File: test.dll
READOBJ-NEXT: Format: COFF-import-file
READOBJ-NEXT: Type: data
READOBJ-NEXT: Name type: name
READOBJ-NEXT: Symbol: __imp_dataexp

Creating a new lib containing the existing lib:
RUN: llvm-lib -machine:arm64ec test.lib -out:test2.lib
RUN: llvm-nm --print-armap test2.lib | FileCheck -check-prefix=ARMAP %s

#--- test.def
LIBRARY test.dll
EXPORTS
funcexp
dataexp DATA

0 comments on commit bf0534e

Please sign in to comment.