mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-19 12:40:10 -08:00
radlink: make command-line /INFERASANLIBS:NO disable ASAN library inference without allowing directive to re-enable it
This commit is contained in:
1 parent
c762d1cd71
commit
e162b800d9
3 files changed
+74
-6
No files matched your search
+18
-4
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
global read_only LNK_CmdSwitch g_cmd_switch_map[] =
|
||||
global LNK_CmdSwitch g_cmd_switch_map[] =
|
||||
{
|
||||
{ LNK_CmdSwitch_Null, 0, LNK_CmdValueKind_Null, "", "", "" },
|
||||
{ LNK_CmdSwitch_NotImplemented, 0, LNK_CmdValueKind_Null, "NOT_IMPLEMENTED", "", "" },
|
||||
@@ -34,8 +34,8 @@ global read_only LNK_CmdSwitch g_cmd_switch_map[] =
|
||||
{ LNK_CmdSwitch_Ignore, 0, LNK_CmdValueKind_Scalar, "IGNORE", ":#", "Ignore a warning." },
|
||||
{ LNK_CmdSwitch_ImpLib, 0, LNK_CmdValueKind_Scalar, "IMPLIB", ":FILENAME", "Set file name for the import library." },
|
||||
{ LNK_CmdSwitch_Include, 1, LNK_CmdValueKind_Scalar, "INCLUDE", ":SYMBOL", "Force a link against SYMBOL." },
|
||||
{ LNK_CmdSwitch_InferAsanLibs, 1, LNK_CmdValueKind_Scalar, "INFERASANLIBS", "[:NO]", "No support." },
|
||||
{ LNK_CmdSwitch_InferAsanLibsNo, 1, LNK_CmdValueKind_Null, "INFERASANLIBSNO", "", "No support.", },
|
||||
{ LNK_CmdSwitch_InferAsanLibs, 1, LNK_CmdValueKind_Scalar, "INFERASANLIBS", "[:NO]", "Infer Asan libraries from the link." },
|
||||
{ LNK_CmdSwitch_InferAsanLibsNo, 1, LNK_CmdValueKind_Null, "INFERASANLIBSNO", "", "Disable Asan lib inference.", },
|
||||
{ LNK_CmdSwitch_LargeAddressAware, 0, LNK_CmdValueKind_Scalar, "LARGEADDRESSAWARE", "[:NO]", "For images that can handle addresses > 2GiB." },
|
||||
{ LNK_CmdSwitch_Lib, 0, LNK_CmdValueKind_Null, "LIB", "", "Turn linker into lib.exe." },
|
||||
{ LNK_CmdSwitch_LibPath, 0, LNK_CmdValueKind_Scalar, "LIBPATH", ":DIR", "Add DIR for the linker to search for libraries." },
|
||||
@@ -60,7 +60,7 @@ global read_only LNK_CmdSwitch g_cmd_switch_map[] =
|
||||
{ LNK_CmdSwitch_PdbPageSize, 0, LNK_CmdValueKind_Scalar, "PDBPAGESIZE", ":#", "Page size must be power of two." },
|
||||
{ LNK_CmdSwitch_PdbStripped, 0, LNK_CmdValueKind_Scalar, "PDBSTRIPPED", ":FILENAME", "Create a stripped PDB containing public symbols, a section map, and a list of object files." },
|
||||
{ LNK_CmdSwitch_Release, 1, LNK_CmdValueKind_Null, "RELEASE", "", "Write image checksum." },
|
||||
{ LNK_CmdSwitch_Section, 1, LNK_CmdValueKind_List, "SECTION", ":NAME,ATTRS", "Set output section attributes." },
|
||||
{ LNK_CmdSwitch_Section, 1, LNK_CmdValueKind_List, "SECTION", ":NAME,ATTRS", "Set output section attributes." },
|
||||
{ LNK_CmdSwitch_Stack, 1, LNK_CmdValueKind_List, "STACK", ":RESERVE[,COMMIT]", "Set reserve and commit size for the stack." },
|
||||
{ LNK_CmdSwitch_SubSystem, 1, LNK_CmdValueKind_List, "SUBSYSTEM", ":{CONSOLE|NATIVE|WINDOWS}[,#[.##]]", "Set subsystem for the image." },
|
||||
{ LNK_CmdSwitch_TsAware, 0, LNK_CmdValueKind_Scalar, "TSAWARE", "[:NO]", "Image is terminal server aware." },
|
||||
@@ -1500,6 +1500,20 @@ lnk_apply_cmd_option_to_config(LNK_Config *config, String8 cmd_name, String8 val
|
||||
|
||||
case LNK_CmdSwitch_InferAsanLibs: {
|
||||
lnk_cmd_switch_parse_flag(obj, cmd_switch, value, &config->infer_asan_libs);
|
||||
|
||||
// Make the command-line option /INFERASANLIBS:NO authorative for ASAN library resolution.
|
||||
// The LLVM toolchain passes ASAN libraries explicitly to lld-link, so we need to disable
|
||||
// library inference and reject directives that re-enable it. Otherwise, a stray MSVC
|
||||
// object file could force radlink to pull in duplicate ASAN libraries.
|
||||
if (obj == 0) {
|
||||
LNK_CmdSwitch *cmd = lnk_cmd_switch_from_type(LNK_CmdSwitch_InferAsanLibs);
|
||||
cmd->is_legal_directive = (config->infer_asan_libs == LNK_SwitchState_Yes);
|
||||
}
|
||||
} break;
|
||||
|
||||
case LNK_CmdSwitch_InferAsanLibsNo: {
|
||||
String8 infer_asan_libs_name = lnk_string_from_cmd_switch_type(LNK_CmdSwitch_InferAsanLibsNo);
|
||||
lnk_apply_cmd_option_to_config(config, infer_asan_libs_name, str8_lit("NO"), obj);
|
||||
} break;
|
||||
|
||||
case LNK_CmdSwitch_LargeAddressAware: {
|
||||
|
||||
@@ -913,14 +913,14 @@ lnk_parse_msvc_linker_directive(Arena *arena, LNK_Obj *obj, LNK_DirectiveInfo *d
|
||||
String8List arg_list = lnk_arg_list_parse_windows_rules(scratch.arena, to_parse);
|
||||
LNK_CmdLine cmd_line = lnk_cmd_line_parse_windows_rules(scratch.arena, arg_list);
|
||||
|
||||
for (LNK_CmdOption *opt = cmd_line.first_option; opt != 0; opt = opt->next) {
|
||||
for EachNode(opt, LNK_CmdOption, cmd_line.first_option) {
|
||||
LNK_CmdSwitch *cmd_switch = lnk_cmd_switch_from_string(opt->string);
|
||||
|
||||
if (cmd_switch == 0) {
|
||||
lnk_error_obj(LNK_Warning_UnknownDirective, obj, "unknown directive \"%S\"", opt->string);
|
||||
continue;
|
||||
}
|
||||
if (!cmd_switch->is_legal_directive) {
|
||||
if (cmd_switch->is_legal_directive == 0) {
|
||||
lnk_error_obj(LNK_Warning_IllegalDirective, obj, "illegal directive \"%S\"", opt->string);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -8127,6 +8127,60 @@ TEST(whole_archive)
|
||||
T_Ok(b_sect != 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST(infer_asan_command_line_no)
|
||||
{
|
||||
Linker linker = t_id_linker();
|
||||
if (linker != Linker_Null && linker != Linker_radlink) { return; }
|
||||
|
||||
T_Ok(t_write_entry_obj());
|
||||
|
||||
// Model LLVM's explicitly supplied runtime and an inferred MSVC runtime thunk
|
||||
// defining the same symbol. Use local stub libraries so no ASAN installation is needed.
|
||||
T_COFF_DefLib runtime = {
|
||||
.emit_second_member = 1,
|
||||
.members = (T_COFF_DefLibMember[]){
|
||||
{
|
||||
.type = T_COFF_DefLibMember_Obj,
|
||||
.obj = {
|
||||
.sections = (T_COFF_DefSection[]){
|
||||
{ "text", ".text", str8_lit_comp("\xC3"), .flags = "rx:code" },
|
||||
{0}
|
||||
},
|
||||
.symbols = (T_COFF_DefSymbol[]){
|
||||
T_COFF_DefSymbol_Extern("asan_runtime", "text", 0),
|
||||
{0}
|
||||
}
|
||||
}
|
||||
},
|
||||
{0}
|
||||
}
|
||||
};
|
||||
T_Ok(t_write_def_lib("explicit_asan.lib", runtime));
|
||||
T_Ok(t_write_def_lib("clang_rt.asan_dynamic_runtime_thunk-x86_64.lib", runtime));
|
||||
T_Ok(t_write_def_lib("clang_rt.asan_dynamic-x86_64.lib", (T_COFF_DefLib){ .emit_second_member = 1 }));
|
||||
T_Ok(t_write_def_lib("msvcrt.lib", (T_COFF_DefLib){ .emit_second_member = 1 }));
|
||||
|
||||
char *args = "/entry:entry /subsystem:console /out:asan.exe /include:asan_runtime entry.obj explicit_asan.lib msvcrt.lib";
|
||||
String8 illegal_directive = str8_lit("illegal directive \"INFERASANLIBS\"");
|
||||
String8 directives[] = { str8_lit("/INFERASANLIBS"), str8_lit("/INFERASANLIBS:YES") };
|
||||
for EachElement(i, directives) {
|
||||
T_Ok(t_write_file(str8_lit("msvc.obj"), t_make_obj_with_directive(arena, directives[i])));
|
||||
|
||||
// Without a command-line override, the directive pulls in the duplicate thunk.
|
||||
t_invoke_linkerf("%s msvc.obj", args);
|
||||
T_Ok(g_last_exit_code == LNK_Error_MultiplyDefinedSymbol);
|
||||
T_Ok(str8_find_needle(g_errors, 0, illegal_directive, 0) == g_errors.size);
|
||||
|
||||
// /NO must reject the directive and leave the explicit runtime as the sole provider.
|
||||
t_invoke_linkerf("%s /INFERASANLIBS:NO msvc.obj", args);
|
||||
T_Ok(g_last_exit_code == 0);
|
||||
T_Ok(str8_find_needle(g_errors, 0, illegal_directive, 0) < g_errors.size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OS_WINDOWS
|
||||
|
||||
internal B32
|
||||
|
||||
Reference in new issue
Block a user