helpers for matching string literals

This commit is contained in:
Nikita Smith
2025-01-18 17:39:11 -08:00
parent 89ff4d0de2
commit a1d5837ff3
13 changed files with 165 additions and 196 deletions
+6 -6
View File
@@ -770,7 +770,7 @@ lnk_make_res_obj(TP_Context *tp,
LNK_RelocList reloc_list = {0};
LNK_RelocList res_data_reloc_list = {0};
for (LNK_Reloc *reloc = sect->reloc_list.first; reloc != 0; reloc = reloc->next) {
B32 is_reloc_symbol = str8_match(str8_lit("$R"), reloc->symbol->name, StringMatchFlag_RightSideSloppy);
B32 is_reloc_symbol = str8_match_lit("$R", reloc->symbol->name, StringMatchFlag_RightSideSloppy);
LNK_Reloc *dst;
if (is_reloc_symbol) {
dst = lnk_reloc_list_push(sect->arena, &res_data_reloc_list);
@@ -2464,7 +2464,7 @@ THREAD_POOL_TASK_FUNC(lnk_weak_symbol_finder)
case COFF_WeakExtType_SEARCH_ALIAS: {
lazy = lnk_symbol_table_search(task->symtab, LNK_SymbolScopeFlag_Lib, symbol->name);
if (!lazy) {
if (str8_match(str8_lit(".weak."), symbol->name, StringMatchFlag_RightSideSloppy)) {
if (str8_match_lit(".weak.", symbol->name, StringMatchFlag_RightSideSloppy)) {
// TODO: Clang and MingGW encode extra info in alias
//
// __attribute__((weak,alias("foo"))) void bar(void);
@@ -3349,13 +3349,13 @@ lnk_run(int argc, char **argv)
// redirect user entry to appropriate CRT entry
if (entry_point_symbol) {
config->entry_point_name = entry_point_symbol->name;
if (str8_match(config->entry_point_name, str8_lit("wmain"), 0)) {
if (str8_match_lit("wmain", config->entry_point_name, 0)) {
config->entry_point_name = str8_lit("wmainCRTStartup");
} else if (str8_match(config->entry_point_name, str8_lit("main"), 0)) {
} else if (str8_match_lit("main", config->entry_point_name, 0)) {
config->entry_point_name = str8_lit("mainCRTStartup");
} else if (str8_match(config->entry_point_name, str8_lit("WinMain"), 0)) {
} else if (str8_match_lit("WinMain", config->entry_point_name, 0)) {
config->entry_point_name = str8_lit("WinMainCRTStartup");
} else if (str8_match(config->entry_point_name, str8_lit("wWinMain"), 0)) {
} else if (str8_match_lit("wWinMain", config->entry_point_name, 0)) {
config->entry_point_name = str8_lit("wWinMainCRTStartup");
}
}
+3 -3
View File
@@ -135,8 +135,8 @@ lnk_cmd_line_parse_windows_rules(Arena *arena, String8List arg_list)
for (String8Node *arg_node = arg_list.first; arg_node != 0; arg_node = arg_node->next) {
String8 arg = arg_node->string;
B32 is_option = str8_match(str8_lit("/"), arg, StringMatchFlag_RightSideSloppy) ||
str8_match(str8_lit("-"), arg, StringMatchFlag_RightSideSloppy);
B32 is_option = str8_match_lit("/", arg, StringMatchFlag_RightSideSloppy) ||
str8_match_lit("-", arg, StringMatchFlag_RightSideSloppy);
if (is_option) {
U64 param_start_pos = str8_find_needle(arg, 0, str8_lit(":"), 0);
String8 option_name = str8_chop(arg, arg.size - param_start_pos);
@@ -195,7 +195,7 @@ lnk_unwrap_rsp(Arena *arena, String8List arg_list)
String8List result = {0};
for (String8Node *curr = arg_list.first; curr != 0; curr = curr->next) {
B32 is_rsp = str8_match(str8_lit("@"), curr->string, StringMatchFlag_RightSideSloppy);
B32 is_rsp = str8_match_lit("@", curr->string, StringMatchFlag_RightSideSloppy);
if (is_rsp) {
// remove "@"
String8 name = str8_skip(curr->string, 1);
+107 -141
View File
@@ -4,7 +4,7 @@
////////////////////////////////
// Enum <-> String
read_only struct
global read_only struct
{
LNK_CmdSwitchType type;
char *name;
@@ -164,12 +164,45 @@ read_only struct
{ LNK_CmdSwitch_Help, "?", "", "" },
};
global read_only struct
{
char *name;
LNK_InputType type;
} g_input_type_map[] = {
{ "o", LNK_Input_Obj },
{ "obj", LNK_Input_Obj },
{ "lib", LNK_Input_Lib },
{ "rlib", LNK_Input_Lib }, // rust libs
{ "res", LNK_Input_Res },
};
global read_only struct
{
char *name;
LNK_DebugMode mode;
} g_debug_mode_map[] = {
{ "null", LNK_DebugMode_Null },
{ "none", LNK_DebugMode_None },
{ "fastlink", LNK_DebugMode_FastLink },
{ "ghash", LNK_DebugMode_GHash },
{ "full", LNK_DebugMode_Full },
};
global read_only struct
{
char *name;
LNK_TypeNameHashMode mode;
} g_type_name_hash_mode_map[] = {
{ "none", LNK_TypeNameHashMode_None },
{ "lenient", LNK_TypeNameHashMode_Lenient },
{ "full", LNK_TypeNameHashMode_Full }
};
internal LNK_CmdSwitchType
lnk_cmd_switch_type_from_string(String8 name)
{
for (U64 i = 0; i < ArrayCount(g_cmd_switch_map); ++i) {
String8 curr_name = str8_cstring(g_cmd_switch_map[i].name);
if (str8_match(curr_name, name, StringMatchFlag_CaseInsensitive)) {
for (U64 i = 0; i < ArrayCount(g_cmd_switch_map); i += 1) {
if (str8_match_cstr(g_cmd_switch_map[i].name, name, StringMatchFlag_CaseInsensitive)) {
return g_cmd_switch_map[i].type;
}
}
@@ -184,69 +217,36 @@ lnk_string_from_cmd_switch_type(LNK_CmdSwitchType type)
return str8_cstring(g_cmd_switch_map[cmd_idx].name);
}
}
return str8(0,0);
return str8_zero();
}
read_only struct {
char *name;
LNK_InputType type;
} g_input_type_map[] = {
{ "o", LNK_Input_Obj },
{ "obj", LNK_Input_Obj },
{ "lib", LNK_Input_Lib },
{ "rlib", LNK_Input_Lib }, // rust libs
{ "res", LNK_Input_Res },
};
internal LNK_InputType
lnk_input_type_from_string(String8 string)
lnk_input_type_from_string(String8 name)
{
for (U64 i = 0; i < ArrayCount(g_input_type_map); i += 1) {
if (str8_match(str8_cstring(g_input_type_map[i].name), string, StringMatchFlag_CaseInsensitive)) {
if (str8_match_cstr(g_input_type_map[i].name, name, StringMatchFlag_CaseInsensitive)) {
return g_input_type_map[i].type;
}
}
return LNK_Input_Null;
}
read_only struct
{
char *name;
LNK_DebugMode mode;
} g_debug_mode_map[] = {
{ "null", LNK_DebugMode_Null },
{ "none", LNK_DebugMode_None },
{ "fastlink", LNK_DebugMode_FastLink },
{ "ghash", LNK_DebugMode_GHash },
{ "full", LNK_DebugMode_Full },
};
internal LNK_DebugMode
lnk_debug_mode_from_string(String8 string)
lnk_debug_mode_from_string(String8 name)
{
for (U64 i = 0; i < ArrayCount(g_debug_mode_map); i += 1) {
if (str8_match(str8_cstring(g_debug_mode_map[i].name), string, StringMatchFlag_CaseInsensitive)) {
if (str8_match_cstr(g_debug_mode_map[i].name, name, StringMatchFlag_CaseInsensitive)) {
return g_debug_mode_map[i].mode;
}
}
return LNK_DebugMode_Null;
}
read_only struct
{
char *name;
LNK_TypeNameHashMode mode;
} g_type_name_hash_mode_map[] = {
{ "none", LNK_TypeNameHashMode_None },
{ "lenient", LNK_TypeNameHashMode_Lenient },
{ "full", LNK_TypeNameHashMode_Full }
};
internal LNK_TypeNameHashMode
lnk_type_name_hash_mode_from_string(String8 string)
lnk_type_name_hash_mode_from_string(String8 name)
{
for (U64 i = 0; i < ArrayCount(g_type_name_hash_mode_map); ++i) {
if (str8_match(str8_cstring(g_type_name_hash_mode_map[i].name), string, StringMatchFlag_CaseInsensitive)) {
for (U64 i = 0; i < ArrayCount(g_type_name_hash_mode_map); i += 1) {
if (str8_match_cstr(g_type_name_hash_mode_map[i].name, name, StringMatchFlag_CaseInsensitive)) {
return g_type_name_hash_mode_map[i].mode;
}
}
@@ -296,16 +296,12 @@ internal void
lnk_error_cmd_switch(LNK_ErrorCode code, String8 obj_path, String8 lib_path, LNK_CmdSwitchType cmd_switch, char *fmt, ...)
{
Temp scratch = scratch_begin(0,0);
va_list args; va_start(args, fmt);
String8 switch_name = lnk_string_from_cmd_switch_type(cmd_switch);
String8 message = push_str8fv(scratch.arena, fmt, args);
String8 output = push_str8f(scratch.arena, "/%S: %S", switch_name, message);
lnk_error_with_loc(code, obj_path, lib_path, "%S", output);
va_end(args);
scratch_end(scratch);
}
@@ -325,9 +321,9 @@ internal String8
lnk_error_check_and_strip_quotes(LNK_ErrorCode error_code, String8 obj_path, String8 lib_path, LNK_CmdSwitchType cmd_switch, String8 string)
{
String8 result = string;
B32 starts_with_quote = str8_match(str8_lit("\""), string, StringMatchFlag_RightSideSloppy);
B32 starts_with_quote = str8_match_lit("\"", string, StringMatchFlag_RightSideSloppy);
if (starts_with_quote) {
if (str8_ends_with(string, str8_lit("\""), 0)) {
if (str8_ends_with_lit(string, "\"", 0)) {
result = str8_skip(result, 1);
result = str8_chop(result, 1);
} else {
@@ -396,55 +392,45 @@ lnk_get_default_subsystem_version(PE_WindowsSubsystem subsystem, COFF_MachineTyp
{
Version ver = make_version(0,0);
switch (subsystem) {
case PE_WindowsSubsystem_WINDOWS_BOOT_APPLICATION: {
ver = make_version(1,0);
} break;
case PE_WindowsSubsystem_WINDOWS_BOOT_APPLICATION: ver = make_version(1,0); break;
case PE_WindowsSubsystem_WINDOWS_CUI: {
switch (machine) {
case COFF_MachineType_X64:
case COFF_MachineType_X86: {
ver = make_version(6,0);
} break;
case COFF_MachineType_X86: ver = make_version(6,0); break;
case COFF_MachineType_ARMNT:
case COFF_MachineType_ARM64:
case COFF_MachineType_ARM: {
ver = make_version(6,2);
} break;
default: { InvalidPath; } break;
case COFF_MachineType_ARM: ver = make_version(6,2); break;
default: lnk_not_implemented("define subsystem(%S) version for %S", pe_string_from_subsystem(subsystem), coff_string_from_machine_type(machine)); break;
}
} break;
case PE_WindowsSubsystem_WINDOWS_GUI: {
switch (machine) {
case COFF_MachineType_X64:
case COFF_MachineType_X86: {
ver = make_version(6,0);
} break;
case COFF_MachineType_X86: ver = make_version(6,0); break;
case COFF_MachineType_ARMNT:
case COFF_MachineType_ARM64:
case COFF_MachineType_ARM: {
ver = make_version(6,2);
} break;
default: { InvalidPath; } break;
case COFF_MachineType_ARM: ver = make_version(6,2); break;
default: lnk_not_implemented("define subsystem(%S) version for %S", pe_string_from_subsystem(subsystem), coff_string_from_machine_type(machine)); break;
}
} break;
case PE_WindowsSubsystem_POSIX_CUI: {
ver = make_version(19,90);
} break;
case PE_WindowsSubsystem_POSIX_CUI: ver = make_version(19,90); break;
case PE_WindowsSubsystem_EFI_APPLICATION:
case PE_WindowsSubsystem_EFI_BOOT_SERVICE_DRIVER:
case PE_WindowsSubsystem_EFI_ROM:
case PE_WindowsSubsystem_EFI_RUNTIME_DRIVER: {
ver = make_version(1,0);
} break;
case PE_WindowsSubsystem_EFI_RUNTIME_DRIVER: ver = make_version(1,0); break;
case PE_WindowsSubsystem_NATIVE_WINDOWS:
case PE_WindowsSubsystem_NATIVE: {
Assert(!"TODO: detect -drive=WDM switch");
} break;
case PE_WindowsSubsystem_NATIVE: lnk_not_implemented("detect -drive=WDM switch"); break;
default: lnk_not_implemented("unknown subsystem kind %u", subsystem); break;
}
return ver;
}
@@ -454,65 +440,47 @@ lnk_get_min_subsystem_version(PE_WindowsSubsystem subsystem, COFF_MachineType ma
{
Version ver = make_version(0,0);
switch (subsystem) {
case PE_WindowsSubsystem_WINDOWS_BOOT_APPLICATION: {
ver = make_version(1,0);
} break;
case PE_WindowsSubsystem_WINDOWS_BOOT_APPLICATION: ver = make_version(1,0); break;
case PE_WindowsSubsystem_WINDOWS_CUI: {
switch (machine) {
case COFF_MachineType_X86: {
ver = make_version(5,1);
} break;
case COFF_MachineType_X86: ver = make_version(5,1); break;
case COFF_MachineType_X64: {
ver = make_version(5,2);
} break;
case COFF_MachineType_X64: ver = make_version(5,2); break;
case COFF_MachineType_ARMNT:
case COFF_MachineType_ARM64:
case COFF_MachineType_ARM: {
ver = make_version(6,2);
} break;
case COFF_MachineType_ARM: ver = make_version(6,2); break;
default: InvalidPath; break;
default: lnk_not_implemented("define min subsystem(%S) version for %S", pe_string_from_subsystem(subsystem), coff_string_from_machine_type(machine)); break;
}
} break;
case PE_WindowsSubsystem_WINDOWS_GUI: {
switch (machine) {
case COFF_MachineType_X86: {
ver = make_version(5,1);
} break;
case COFF_MachineType_X86: ver = make_version(5,1); break;
case COFF_MachineType_X64: {
ver = make_version(5,2);
} break;
case COFF_MachineType_X64: ver = make_version(5,2); break;
case COFF_MachineType_ARMNT:
case COFF_MachineType_ARM64:
case COFF_MachineType_ARM: {
ver = make_version(6,2);
} break;
case COFF_MachineType_ARM: ver = make_version(6,2); break;
default: InvalidPath; break;
default: lnk_not_implemented("define min subsystem(%S) version for %S", pe_string_from_subsystem(subsystem), coff_string_from_machine_type(machine)); break;
}
} break;
case PE_WindowsSubsystem_POSIX_CUI: {
ver = make_version(1,0);
} break;
case PE_WindowsSubsystem_POSIX_CUI: ver = make_version(1,0); break;
case PE_WindowsSubsystem_EFI_APPLICATION:
case PE_WindowsSubsystem_EFI_BOOT_SERVICE_DRIVER:
case PE_WindowsSubsystem_EFI_ROM:
case PE_WindowsSubsystem_EFI_RUNTIME_DRIVER: {
ver = make_version(1,0);
} break;
case PE_WindowsSubsystem_EFI_RUNTIME_DRIVER: ver = make_version(1,0); break;
case PE_WindowsSubsystem_NATIVE_WINDOWS:
case PE_WindowsSubsystem_NATIVE: {
Assert(!"TODO: detect -drive=WDM switch");
} break;
case PE_WindowsSubsystem_NATIVE: lnk_not_implemented("detect -drive=WDM switch"); break;
default: lnk_not_implemented("unknown subsystem kind %u", subsystem);
}
return ver;
}
@@ -607,7 +575,6 @@ lnk_try_parse_u64(String8 string, LNK_ParseU64Flags flags, U64 *value_out)
return 0;
}
}
if (flags & LNK_ParseU64Flag_CheckPow2) {
if (!IsPow2(*value_out)) {
return 0;
@@ -663,10 +630,10 @@ lnk_cmd_switch_parse_flag(String8 obj_path, String8 lib_path, LNK_CmdSwitchType
if (value_strings.node_count > 1) {
lnk_error_cmd_switch(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, "too many parameters");
} else if (value_strings.node_count == 1) {
if (str8_match(value_strings.first->string, str8_lit("no"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("no", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
*value_out = LNK_SwitchState_No;
is_parsed = 1;
} else if (str8_match(value_strings.first->string, str8_lit("yes"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("yes", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
*value_out = LNK_SwitchState_Yes;
is_parsed = 1;
} else if (value_strings.first->string.size == 0) {
@@ -1021,7 +988,7 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
if (value_strings.node_count == 2) {
String8Node *first_node = value_strings.first;
//String8Node *second_node = first_node->next;
B32 is_response_file = str8_match(str8_lit("@"), first_node->string, StringMatchFlag_RightSideSloppy);
B32 is_response_file = str8_match_lit("@", first_node->string, StringMatchFlag_RightSideSloppy);
if (is_response_file) {
//String8 file_path = first_node->string;
//String8 tag = second_node->string;
@@ -1076,9 +1043,9 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
lnk_error_cmd_switch(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, "invalid number of parameters");
} else {
String8 value = value_strings.first->string;
if (str8_match(value, str8_lit("unload"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("unload", value, StringMatchFlag_CaseInsensitive)) {
config->flags |= LNK_ConfigFlag_DelayUnload;
} else if (str8_match(value, str8_lit("nobind"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("nobind", value, StringMatchFlag_CaseInsensitive)) {
config->flags &= ~LNK_ConfigFlag_DelayBind;
} else {
lnk_error_cmd_switch(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, "unknown parameter \"%S\"", value);
@@ -1241,14 +1208,13 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
String8List param_list = str8_split_by_string_chars(scratch.arena, value_strings.first->string, str8_lit(","), 0);
String8Array param_arr = str8_array_from_list(scratch.arena, &param_list);
if (param_arr.count > 0) {
if (str8_match(param_arr.v[0], str8_lit("embed"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("embed", param_arr.v[0], StringMatchFlag_CaseInsensitive)) {
config->manifest_opt = LNK_ManifestOpt_Embed;
if (param_arr.count == 1) {
config->manifest_resource_id = 0;
} else if (param_arr.count > 1) {
// parse resource id
if (str8_match(param_arr.v[1], str8_lit("id="), StringMatchFlag_RightSideSloppy|StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("id=", param_arr.v[1], StringMatchFlag_RightSideSloppy|StringMatchFlag_CaseInsensitive)) {
String8List res_id_list = str8_split_by_string_chars(scratch.arena, param_arr.v[1], str8_lit("="), 0);
String8Array res_id_arr = str8_array_from_list(scratch.arena, &res_id_list);
if (res_id_arr.count == 2) {
@@ -1267,7 +1233,7 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
} else {
lnk_error_cmd_switch_invalid_param_count(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch);
}
} else if (str8_match(param_arr.v[0], str8_lit("no"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("no", param_arr.v[0], StringMatchFlag_CaseInsensitive)) {
config->manifest_opt = LNK_ManifestOpt_No;
} else {
lnk_error_cmd_switch_invalid_param(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, param_arr.v[0]);
@@ -1305,15 +1271,15 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
String8List param_list = str8_split_by_string_chars(scratch.arena, uac, str8_lit(" "), 0);
String8Array param_arr = str8_array_from_list(scratch.arena, &param_list);
if (param_arr.count > 0) {
if (str8_match(str8_lit("level="), param_arr.v[0], StringMatchFlag_RightSideSloppy|StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("level=", param_arr.v[0], StringMatchFlag_RightSideSloppy|StringMatchFlag_CaseInsensitive)) {
String8 level_param = param_arr.v[0];
String8List level_list = str8_split_by_string_chars(scratch.arena, level_param, str8_lit("="), 0);
if (level_list.node_count == 2) {
if (str8_match(level_list.first->string, str8_lit("level"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("level", level_list.first->string, StringMatchFlag_CaseInsensitive)) {
String8 level = level_list.last->string;
if (str8_match(level, str8_lit("'asInvoker'"), 0) ||
str8_match(level, str8_lit("'highestAvailable'"), 0) ||
str8_match(level, str8_lit("'requireAdministrator'"), 0)) {
if (str8_match_lit("'asInvoker'", level, 0) ||
str8_match_lit("'highestAvailable'", level, 0) ||
str8_match_lit("'requireAdministrator'", level, 0)) {
// manifest level was parsed!
config->manifest_uac = 1;
config->manifest_level = push_str8_copy(arena, level);
@@ -1322,8 +1288,8 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
String8List ui_access_list = str8_split_by_string_chars(scratch.arena, ui_access_param, str8_lit("="), 0);
if (ui_access_list.node_count == 2) {
String8 ui_access = ui_access_list.last->string;
if (str8_match(ui_access, str8_lit("'true'"), 0) ||
str8_match(ui_access, str8_lit("'false'"), 0)) {
if (str8_match_lit("'true'", ui_access, 0) ||
str8_match_lit("'false'", ui_access, 0)) {
// ui access was parsed!
config->manifest_ui_access = push_str8_copy(arena, ui_access);
} else {
@@ -1342,7 +1308,7 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
} else {
lnk_error_invalid_uac_level_param(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, level_param);
}
} else if (str8_match(str8_lit("no"), param_arr.v[0], StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("no", param_arr.v[0], StringMatchFlag_CaseInsensitive)) {
config->manifest_uac = 0;
} else {
lnk_error_cmd_switch_invalid_param(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, param_arr.v[0]);
@@ -1359,7 +1325,7 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
// warn about invalid natvis extension
for (String8Node *node = value_strings.first; node != 0; node = node->next) {
String8 ext = str8_skip_last_dot(node->string);
if (!str8_match(ext, str8_lit("natvis"), StringMatchFlag_CaseInsensitive)) {
if (!str8_match_lit("natvis", ext, StringMatchFlag_CaseInsensitive)) {
lnk_error_cmd_switch(LNK_Warning_InvalidNatvisFileExt, obj_path, lib_path, cmd_switch, "Visual Studio expects .natvis extension: \"%S\"", node->string);
}
}
@@ -1396,12 +1362,12 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
case LNK_CmdSwitch_Opt: {
for (String8Node *n = value_strings.first; n != 0; n = n->next) {
String8 param = n->string;
if (str8_match(param, str8_lit("ref"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("ref", param, StringMatchFlag_CaseInsensitive)) {
config->opt_ref = LNK_SwitchState_Yes;
} else if (str8_match(param, str8_lit("noref"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("noref", param, StringMatchFlag_CaseInsensitive)) {
config->opt_ref = LNK_SwitchState_No;
} else if (str8_match(param, str8_lit("icf"), StringMatchFlag_CaseInsensitive) ||
str8_match(param, str8_lit("icf="), StringMatchFlag_CaseInsensitive | StringMatchFlag_RightSideSloppy)) {
} else if (str8_match_lit("icf", param, StringMatchFlag_CaseInsensitive) ||
str8_match_lit("icf=", param, StringMatchFlag_CaseInsensitive | StringMatchFlag_RightSideSloppy)) {
String8List vals = str8_split_by_string_chars(scratch.arena, param, str8_lit("="), 0);
if (vals.node_count > 2) {
lnk_error_cmd_switch(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, "too many parameters for iteration");
@@ -1415,11 +1381,11 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
}
}
config->opt_icf = LNK_SwitchState_Yes;
} else if (str8_match(param, str8_lit("noicf"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("noicf", param, StringMatchFlag_CaseInsensitive)) {
config->opt_icf = LNK_SwitchState_No;
} else if (str8_match(param, str8_lit("lbr"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("lbr", param, StringMatchFlag_CaseInsensitive)) {
config->opt_lbr = LNK_SwitchState_Yes;
} else if (str8_match(param, str8_lit("nolibr"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("nolibr", param, StringMatchFlag_CaseInsensitive)) {
config->opt_lbr = LNK_SwitchState_No;
} else {
lnk_error_cmd_switch(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, "unknown option \"%S\"", param);
@@ -1566,9 +1532,9 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
case LNK_CmdSwitch_Rad_Guid: {
if (value_strings.node_count == 1) {
if (str8_match(value_strings.first->string, str8_lit("imageblake3"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("imageblake3", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
config->guid_type = Lnk_DebugInfoGuid_ImageBlake3;
} else if (str8_match(value_strings.first->string, str8_lit("random"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("random", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
config->guid = os_make_guid();
} else {
Guid guid;
@@ -1605,12 +1571,12 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
#endif
}
} else if (value_strings.node_count == 1) {
if (str8_match(value_strings.first->string, str8_lit("quiet"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("quiet", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
OS_ProcessInfo *process_info = os_get_process_info();
if (process_info->large_pages_allowed) {
arena_default_flags |= ArenaFlag_LargePages;
}
} else if (str8_match(value_strings.first->string, str8_lit("no"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("no", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
arena_default_flags &= ~ArenaFlag_LargePages;
} else {
lnk_error_cmd_switch(LNK_Error_Cmdl, obj_path, lib_path, cmd_switch, "invalid parameter: \"%S\", expected NO or QUIET", value_strings.first->string);
@@ -1626,11 +1592,11 @@ lnk_apply_cmd_option_to_config(Arena *arena, LNK_Config *config, String8 cmd_nam
case LNK_CmdSwitch_Rad_Log: {
if (value_strings.node_count == 1) {
if (str8_match(value_strings.first->string, str8_lit("all"), StringMatchFlag_CaseInsensitive)) {
if (str8_match_lit("all", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
for (U64 ilog = 0; ilog < LNK_Log_Count; ilog += 1) {
lnk_set_log_status((LNK_LogType)ilog, 1);
}
} else if (str8_match(value_strings.first->string, str8_lit("io"), StringMatchFlag_CaseInsensitive)) {
} else if (str8_match_lit("io", value_strings.first->string, StringMatchFlag_CaseInsensitive)) {
lnk_set_log_status(LNK_Log_IO_Read, 1);
lnk_set_log_status(LNK_Log_IO_Write, 1);
} else {
+2 -2
View File
@@ -542,7 +542,7 @@ lnk_build_import_entry_obj(Arena *arena, String8 dll_name, COFF_MachineType mach
ProfBeginFunction();
Assert(machine == COFF_MachineType_X64);
Assert(str8_match(str8_lit("dll"), str8_skip_last_dot(dll_name), StringMatchFlag_CaseInsensitive|StringMatchFlag_RightSideSloppy));
Assert(str8_match_lit("dll", str8_skip_last_dot(dll_name), StringMatchFlag_CaseInsensitive|StringMatchFlag_RightSideSloppy));
String8List list = {0};
@@ -802,7 +802,7 @@ lnk_build_null_thunk_data_obj(Arena *arena, String8 dll_name, COFF_MachineType m
{
ProfBeginFunction();
Assert(str8_match(str8_lit("dll"), str8_skip_last_dot(dll_name), StringMatchFlag_CaseInsensitive|StringMatchFlag_RightSideSloppy));
Assert(str8_match_lit("dll", str8_skip_last_dot(dll_name), StringMatchFlag_CaseInsensitive|StringMatchFlag_RightSideSloppy));
String8List list = {0};
+1 -1
View File
@@ -1119,7 +1119,7 @@ lnk_directive_info_from_sections(Arena *arena,
for (U64 chunk_idx = 0; chunk_idx < chunk_count; ++chunk_idx) {
String8 sect_name = sect_name_arr[chunk_idx];
LNK_Chunk *sect_chunk = chunk_arr + chunk_idx;
if (str8_match(sect_name, str8_lit(".drectve"), 0)) {
if (str8_match_lit(".drectve", sect_name, 0)) {
if (sect_chunk->type == LNK_Chunk_Leaf) {
if (sect_chunk->u.leaf.size >= 3) {
if (~sect_chunk->flags & COFF_SectionFlag_LNK_INFO) {
+7 -7
View File
@@ -91,10 +91,10 @@ lnk_make_section_sort_index(Arena *arena, String8 name, COFF_SectionFlags flags,
str8_list_pushf(scratch.arena, &sort_index_list, "a");
}
if (str8_match(name, str8_lit(".null"), 0)) {
if (str8_match_lit(".null", name, 0)) {
// null section always first
str8_list_pushf(scratch.arena, &sort_index_list, "a");
} else if (str8_match(name, str8_lit(".rsrc"), 0)) {
} else if (str8_match_lit(".rsrc", name, 0)) {
// section with resource data must be last because during runtime windows might append pages
str8_list_pushf(scratch.arena, &sort_index_list, "c");
} else {
@@ -104,18 +104,18 @@ lnk_make_section_sort_index(Arena *arena, String8 name, COFF_SectionFlags flags,
// sort sections based on the contents
if (flags & COFF_SectionFlag_CNT_CODE) {
str8_list_pushf(scratch.arena, &sort_index_list, "a");
if (str8_match(name, str8_lit(".text"), 0)) {
if (str8_match_lit(".text", name, 0)) {
str8_list_pushf(scratch.arena, &sort_index_list, "a");
} else {
str8_list_pushf(scratch.arena, &sort_index_list, "b");
}
} else if (flags & COFF_SectionFlag_CNT_INITIALIZED_DATA) {
str8_list_pushf(scratch.arena, &sort_index_list, "b");
if (str8_match(name, str8_lit(".data"), 0)) {
if (str8_match_lit(".data", name, 0)) {
str8_list_pushf(scratch.arena, &sort_index_list, "a");
} else if (str8_match(name, str8_lit(".rdata"), 0)) {
} else if (str8_match_lit(".rdata", name, 0)) {
str8_list_pushf(scratch.arena, &sort_index_list, "b");
} else if (str8_match(name, str8_lit(".tls"), 0)) {
} else if (str8_match_lit(".tls", name, 0)) {
str8_list_pushf(scratch.arena, &sort_index_list, "c");
} else {
str8_list_pushf(scratch.arena, &sort_index_list, "d");
@@ -888,7 +888,7 @@ lnk_dump_chunks(LNK_SectionTable *st)
LNK_Section *sect = sect_id_map[sect_id];
if (!sect) continue;
if (sect->is_merged) continue;
if (str8_match(sect->name, str8_lit(".text"), 0)) {
if (str8_match_lit(".text", sect->name, 0)) {
for (U64 chunk_id = 0; chunk_id < sect->cman->total_chunk_count; ++chunk_id) {
LNK_ChunkRef chunk_ref = { sect_id, chunk_id };
LNK_Chunk *chunk = lnk_chunk_from_chunk_ref(sect_id_map, chunk_id_map, chunk_ref);