diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 3fde9c84d977d..6eea11f5f451f 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1795,6 +1795,9 @@ void LinkerDriver::linkerMain(ArrayRef argsArr) { setMachine(machine); } } + + // Most of main arguments apply either to both or only to EC symbol table on + // ARM64X target. SymbolTable &mainSymtab = ctx.hybridSymtab ? *ctx.hybridSymtab : ctx.symtab; // Handle /nodefaultlib: @@ -2291,6 +2294,12 @@ void LinkerDriver::linkerMain(ArrayRef argsArr) { if (auto *arg = args.getLastArg(OPT_deffile)) { // parseModuleDefs mutates Config object. mainSymtab.parseModuleDefs(arg->getValue()); + if (ctx.hybridSymtab) { + // MSVC ignores the /defArm64Native argument on non-ARM64X targets. + // It is also ignored if the /def option is not specified. + if (auto *arg = args.getLastArg(OPT_defarm64native)) + ctx.symtab.parseModuleDefs(arg->getValue()); + } } // Handle generation of import library from a def file. diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td index c7ceb51f70b70..b6fd3d0daaef9 100644 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -140,6 +140,9 @@ def incl : Joined<["/", "-", "/?", "-?"], "include:">, def deffile : Joined<["/", "-", "/?", "-?"], "def:">, HelpText<"Use module-definition file">; +def defarm64native + : P<"defarm64native", + "Use a module-definition file for the native view in a hybrid image.">; def debug : F<"debug">, HelpText<"Embed a symbol table in the image">; def debug_opt : P<"debug", "Embed a symbol table in the image with option">; def debugtype : P<"debugtype", "Debug Info Options">; diff --git a/lld/test/COFF/arm64x-export.test b/lld/test/COFF/arm64x-export.test index a78b291cedbe1..3ae0725a67089 100644 --- a/lld/test/COFF/arm64x-export.test +++ b/lld/test/COFF/arm64x-export.test @@ -162,6 +162,29 @@ EXPORTS-BOTH-NEXT: RVA: 0x3000 EXPORTS-BOTH-NEXT: } EXPORTS-BOTH-NEXT: } +# Export using both the -def and -defarm64native arguments. + +RUN: lld-link -machine:arm64x -dll -out:out-def-both.dll arm64ec-func.obj arm64-func.obj \ +RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -def:func.def -defarm64native:func.def -noentry +RUN: llvm-objdump -d out-def-both.dll | FileCheck --check-prefix=DISASM-BOTH %s +RUN: llvm-readobj --headers --coff-exports out-def-both.dll | FileCheck --check-prefix=EXPORTS-BOTH %s + +# -defarm64native is ignored if -def is not specified. + +RUN: lld-link -machine:arm64x -dll -out:out-def-native.dll arm64ec-func.obj arm64-func.obj \ +RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -defarm64native:func.def -noentry +RUN: llvm-readobj --headers --coff-exports out-def-native.dll | FileCheck --check-prefix=NO-EXPORT %s +NO-EXPORT: ExportTableRVA: 0x0 +NO-EXPORT: ExportTableSize: 0x0 +NO-EXPORT: HybridObject { +NO-EXPORT: ExportTableRVA: 0x0 +NO-EXPORT: ExportTableSize: 0x0 +NO-EXPORT: } + +# -defarm64native is ignored on ARM64 target. + +RUN: lld-link -machine:arm64 -dll -out:out-arm64-def.dll arm64-func.obj -defarm64native:invalid.def -def:func.def -noentry 2>&1 | count 0 + # Export using both the native and EC .edata sections. RUN: lld-link -machine:arm64x -dll -out:out-edata-both.dll arm64ec-func.obj arm64-func.obj \