mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-30 17:21:10 +00:00
[LLD] [COFF] Add a separate option for allowing duplicate weak symbols (#68077)
The MinGW mode (enabled with the flag -lldmingw) does allow duplicate weak symbols. A test in compiler-rt/test/profile/Windows/coverage-weak-lld.cpp does currently enable the -lldmingw flag in an MSVC context, in order to deal with duplicate weak symbols. Add a new, separate, lld specific flag for enabling this. In MinGW mode, this is enabled by default, otherwise it is disabled. This allows making the MinGW mode more restrictive in adding libpaths from the surrounding environment; in MinGW mode, all libpaths are passed explicitly by the compiler driver to the linker, which is attempted in https://reviews.llvm.org/D144084.
This commit is contained in:
parent
c5dacb6d7a
commit
a67ae8c0fd
@ -316,6 +316,7 @@ struct Configuration {
|
||||
bool stdcallFixup = false;
|
||||
bool writeCheckSum = false;
|
||||
EmitKind emit = EmitKind::Obj;
|
||||
bool allowDuplicateWeak = false;
|
||||
};
|
||||
|
||||
} // namespace lld::coff
|
||||
|
@ -2028,6 +2028,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
|
||||
config->stdcallFixup =
|
||||
args.hasFlag(OPT_stdcall_fixup, OPT_stdcall_fixup_no, config->mingw);
|
||||
config->warnStdcallFixup = !args.hasArg(OPT_stdcall_fixup);
|
||||
config->allowDuplicateWeak =
|
||||
args.hasFlag(OPT_lld_allow_duplicate_weak,
|
||||
OPT_lld_allow_duplicate_weak_no, config->mingw);
|
||||
|
||||
if (args.hasFlag(OPT_inferasanlibs, OPT_inferasanlibs_no, false))
|
||||
warn("ignoring '/inferasanlibs', this flag is not supported");
|
||||
|
@ -81,7 +81,7 @@ static void checkAndSetWeakAlias(COFFLinkerContext &ctx, InputFile *f,
|
||||
// of another symbol emitted near the weak symbol.
|
||||
// Just use the definition from the first object file that defined
|
||||
// this weak symbol.
|
||||
if (ctx.config.mingw)
|
||||
if (ctx.config.allowDuplicateWeak)
|
||||
return;
|
||||
ctx.symtab.reportDuplicate(source, f);
|
||||
}
|
||||
|
@ -232,6 +232,7 @@ defm demangle : B<"demangle",
|
||||
def include_optional : Joined<["/", "-", "/?", "-?"], "includeoptional:">,
|
||||
HelpText<"Add symbol as undefined, but allow it to remain undefined">;
|
||||
def kill_at : F<"kill-at">;
|
||||
defm lld_allow_duplicate_weak : B_priv<"lld-allow-duplicate-weak">;
|
||||
def lldemit : P<"lldemit", "Specify output type">;
|
||||
def lldmingw : F<"lldmingw">;
|
||||
def noseh : F<"noseh">;
|
||||
|
@ -1,4 +1,9 @@
|
||||
RUN: lld-link -lldmingw %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
|
||||
RUN: lld-link -lld-allow-duplicate-weak %S/Inputs/gnu-weak.o %S/Inputs/gnu-weak2.o -out:%t.exe
|
||||
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
|
||||
|
||||
DEFAULT-ERROR: error: duplicate symbol: weakfunc
|
||||
|
||||
|
||||
GNU ld can handle several definitions of the same weak symbol, and
|
||||
unless there is a strong definition of it, it just picks the first
|
||||
|
Loading…
Reference in New Issue
Block a user