Skip to content

Commit ffe3bf3

Browse files
authored
Merge pull request #8959 from hamishknight/dup-weak-6.0
[6.0] [LLD] [COFF] Add a separate option for allowing duplicate weak symbols
2 parents 450d470 + d650dd7 commit ffe3bf3

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

lld/COFF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ struct Configuration {
313313
bool pseudoRelocs = false;
314314
bool stdcallFixup = false;
315315
bool writeCheckSum = false;
316+
bool allowDuplicateWeak = false;
316317
};
317318

318319
} // namespace lld::coff

lld/COFF/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
19801980
config->stdcallFixup =
19811981
args.hasFlag(OPT_stdcall_fixup, OPT_stdcall_fixup_no, config->mingw);
19821982
config->warnStdcallFixup = !args.hasArg(OPT_stdcall_fixup);
1983+
config->allowDuplicateWeak =
1984+
args.hasFlag(OPT_lld_allow_duplicate_weak,
1985+
OPT_lld_allow_duplicate_weak_no, config->mingw);
19831986

19841987
if (args.hasFlag(OPT_inferasanlibs, OPT_inferasanlibs_no, false))
19851988
warn("ignoring '/inferasanlibs', this flag is not supported");

lld/COFF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void checkAndSetWeakAlias(COFFLinkerContext &ctx, InputFile *f,
8181
// of another symbol emitted near the weak symbol.
8282
// Just use the definition from the first object file that defined
8383
// this weak symbol.
84-
if (ctx.config.mingw)
84+
if (ctx.config.allowDuplicateWeak)
8585
return;
8686
ctx.symtab.reportDuplicate(source, f);
8787
}

lld/COFF/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ defm demangle : B<"demangle",
232232
def include_optional : Joined<["/", "-", "/?", "-?"], "includeoptional:">,
233233
HelpText<"Add symbol as undefined, but allow it to remain undefined">;
234234
def kill_at : F<"kill-at">;
235+
defm lld_allow_duplicate_weak : B_priv<"lld-allow-duplicate-weak">;
235236
def lldmingw : F<"lldmingw">;
236237
def noseh : F<"noseh">;
237238
def osversion : P_priv<"osversion">;

lld/test/COFF/gnu-weak.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
RUN: lld-link -lldmingw %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
2+
RUN: lld-link -lld-allow-duplicate-weak %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
3+
RUN: not lld-link %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe 2>&1 | FileCheck %s --check-prefix=DEFAULT-ERROR
4+
5+
DEFAULT-ERROR: error: duplicate symbol: weakfunc
6+
27

38
GNU ld can handle several definitions of the same weak symbol, and
49
unless there is a strong definition of it, it just picks the first

0 commit comments

Comments
 (0)