Skip to content

Commit e38a605

Browse files
committed
[LLD][COFF] Add support for the -defArm64Native argument
MSVC ignores the /defArm64Native argument on non-ARM64X targets. It is also ignored if the /def option is not specified.
1 parent 6e04095 commit e38a605

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lld/COFF/Driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22912291
if (auto *arg = args.getLastArg(OPT_deffile)) {
22922292
// parseModuleDefs mutates Config object.
22932293
mainSymtab.parseModuleDefs(arg->getValue());
2294+
if (ctx.hybridSymtab) {
2295+
// MSVC ignores the /defArm64Native argument on non-ARM64X targets.
2296+
// It is also ignored if the /def option is not specified.
2297+
if (auto *arg = args.getLastArg(OPT_defarm64native))
2298+
ctx.symtab.parseModuleDefs(arg->getValue());
2299+
}
22942300
}
22952301

22962302
// Handle generation of import library from a def file.

lld/COFF/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def incl : Joined<["/", "-", "/?", "-?"], "include:">,
140140
def deffile : Joined<["/", "-", "/?", "-?"], "def:">,
141141
HelpText<"Use module-definition file">;
142142

143+
def defarm64native
144+
: P<"defarm64native",
145+
"Use a module-definition file for the native view in a hybrid image.">;
143146
def debug : F<"debug">, HelpText<"Embed a symbol table in the image">;
144147
def debug_opt : P<"debug", "Embed a symbol table in the image with option">;
145148
def debugtype : P<"debugtype", "Debug Info Options">;

lld/test/COFF/arm64x-export.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ EXPORTS-BOTH-NEXT: RVA: 0x3000
162162
EXPORTS-BOTH-NEXT: }
163163
EXPORTS-BOTH-NEXT: }
164164

165+
# Export using both the -def and -defarm64native arguments.
166+
167+
RUN: lld-link -machine:arm64x -dll -out:out-def-both.dll arm64ec-func.obj arm64-func.obj \
168+
RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -def:func.def -defarm64native:func.def -noentry
169+
RUN: llvm-objdump -d out-def-both.dll | FileCheck --check-prefix=DISASM-BOTH %s
170+
RUN: llvm-readobj --headers --coff-exports out-def-both.dll | FileCheck --check-prefix=EXPORTS-BOTH %s
171+
172+
# -defarm64native is ignored if -def is not specified.
173+
174+
RUN: lld-link -machine:arm64x -dll -out:out-def-native.dll arm64ec-func.obj arm64-func.obj \
175+
RUN: loadconfig-arm64.obj loadconfig-arm64ec.obj -defarm64native:func.def -noentry
176+
RUN: llvm-readobj --headers --coff-exports out-def-native.dll | FileCheck --check-prefix=NO-EXPORT %s
177+
NO-EXPORT: ExportTableRVA: 0x0
178+
NO-EXPORT: ExportTableSize: 0x0
179+
NO-EXPORT: HybridObject {
180+
NO-EXPORT: ExportTableRVA: 0x0
181+
NO-EXPORT: ExportTableSize: 0x0
182+
NO-EXPORT: }
183+
184+
# -defarm64native is ignored on ARM64 target.
185+
186+
RUN: lld-link -machine:arm64 -dll -out:out-arm64-def.dll arm64-func.obj -defarm64native:undef.def -def:func.def -noentry
187+
165188
# Export using both the native and EC .edata sections.
166189

167190
RUN: lld-link -machine:arm64x -dll -out:out-edata-both.dll arm64ec-func.obj arm64-func.obj \

0 commit comments

Comments
 (0)