fix segv about skip_next, warn on unsupported cases of linking options (#1958)

This commit is contained in:
Sonic
2024-01-18 15:56:28 +08:00
committed by GitHub
parent e9621db61c
commit 8412b17d79

View File

@ -1982,7 +1982,7 @@ param_st parse_linking_params(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan,
} else if (!strcmp(cur_argv, "-z") || !strcmp(cur_argv, "-Wl,-z")) { } else if (!strcmp(cur_argv, "-z") || !strcmp(cur_argv, "-Wl,-z")) {
u8 *param = *(argv + 1); u8 *param = *(argv + 1);
if (!strcmp(param, "defs") || !strcmp(param, "-Wl,defs")) { if (param && (!strcmp(param, "defs") || !strcmp(param, "-Wl,defs"))) {
*skip_next = 1; *skip_next = 1;
@ -2000,6 +2000,64 @@ param_st parse_linking_params(aflcc_state_t *aflcc, u8 *cur_argv, u8 scan,
} }
// Try to warn user for some unsupported cases
if (scan && final_ == PARAM_MISS) {
u8 *ptr_ = NULL;
if (!strcmp(cur_argv, "-Xlinker") && (ptr_ = *(argv + 1))) {
if (!strcmp(ptr_, "defs")) {
WARNF("'-Xlinker' 'defs' detected. This may result in a bad link.");
} else if (strstr(ptr_, "-no-undefined")) {
WARNF(
"'-Xlinker' '%s' detected. The latter option may be dropped and "
"result in a bad link.",
ptr_);
}
} else if (!strncmp(cur_argv, "-Wl,", 4) &&
(u8 *)strrchr(cur_argv, ',') != (cur_argv + 3)) {
ptr_ = cur_argv + 4;
if (strstr(ptr_, "-shared") || strstr(ptr_, "-dynamiclib")) {
WARNF(
"'%s': multiple link options after '-Wl,' may break shared "
"linking.",
ptr_);
}
if (strstr(ptr_, "-r,") || strstr(ptr_, "-i,") || strstr(ptr_, ",-r") ||
strstr(ptr_, ",-i") || strstr(ptr_, "--relocatable")) {
WARNF(
"'%s': multiple link options after '-Wl,' may break partial "
"linking.",
ptr_);
}
if (strstr(ptr_, "defs") || strstr(ptr_, "no-undefined")) {
WARNF(
"'%s': multiple link options after '-Wl,' may enable report "
"unresolved symbol references and result in a bad link.",
ptr_);
}
}
}
if (final_ == PARAM_KEEP) insert_param(aflcc, cur_argv); if (final_ == PARAM_KEEP) insert_param(aflcc, cur_argv);
return final_; return final_;