mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-01 21:23:51 -09:00
toolchain/toolchain-wrapper.c: get rid of EXCLUSIVE_ARGS
Rather than having a hard coded amount of exclusive args (with the risk of overflow when new logic is added), simplify the argument buffer allocation logic to always allocate room for DEFAULT_MAX_ARGS (1024) arguments and just realloc to grow for the rare situation where that is not enough. Signed-off-by: Peter Korsgaard <peter@korsgaard.com> Signed-off-by: Julien Olivain <ju.o@free.fr>
This commit is contained in:
committed by
Julien Olivain
parent
6b8ffbf97b
commit
00b30f887a
@@ -36,25 +36,9 @@ static char sysroot[PATH_MAX];
|
|||||||
static char _time_[sizeof("-D__TIME__=\"HH:MM:SS\"")];
|
static char _time_[sizeof("-D__TIME__=\"HH:MM:SS\"")];
|
||||||
static char _date_[sizeof("-D__DATE__=\"MMM DD YYYY\"")];
|
static char _date_[sizeof("-D__DATE__=\"MMM DD YYYY\"")];
|
||||||
|
|
||||||
/**
|
/* Maximum amount of arguments to reserve space for by default.
|
||||||
* GCC errors out with certain combinations of arguments (examples are
|
Must be > predef_args */
|
||||||
* -mfloat-abi={hard|soft} and -m{little|big}-endian), so we have to ensure
|
#define DEFAULT_MAX_ARGS 1024
|
||||||
* that we only pass the predefined one to the real compiler if the inverse
|
|
||||||
* option isn't in the argument list.
|
|
||||||
* This specifies the worst case number of extra arguments we might pass
|
|
||||||
* Currently, we may have:
|
|
||||||
* -mfloat-abi=
|
|
||||||
* -march=
|
|
||||||
* -mcpu=
|
|
||||||
* -D__TIME__=
|
|
||||||
* -D__DATE__=
|
|
||||||
* -Wno-builtin-macro-redefined
|
|
||||||
* -Wl,-z,now
|
|
||||||
* -Wl,-z,relro
|
|
||||||
* -fPIE
|
|
||||||
* -pie
|
|
||||||
*/
|
|
||||||
#define EXCLUSIVE_ARGS 10
|
|
||||||
|
|
||||||
static char *predef_args[] = {
|
static char *predef_args[] = {
|
||||||
#ifdef BR_CCACHE
|
#ifdef BR_CCACHE
|
||||||
@@ -252,6 +236,7 @@ int main(int argc, char **argv)
|
|||||||
char *basename;
|
char *basename;
|
||||||
char *env_debug;
|
char *env_debug;
|
||||||
int ret, i, count = 0, debug = 0, found_shared = 0, found_nonoption = 0;
|
int ret, i, count = 0, debug = 0, found_shared = 0, found_nonoption = 0;
|
||||||
|
size_t n_args;
|
||||||
|
|
||||||
/* Debug the wrapper to see arguments it was called with.
|
/* Debug the wrapper to see arguments it was called with.
|
||||||
* If environment variable BR2_DEBUG_WRAPPER is:
|
* If environment variable BR2_DEBUG_WRAPPER is:
|
||||||
@@ -360,8 +345,7 @@ int main(int argc, char **argv)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = args = malloc(sizeof(predef_args) +
|
cur = args = malloc(DEFAULT_MAX_ARGS * sizeof(char *));
|
||||||
(sizeof(char *) * (argc + EXCLUSIVE_ARGS)));
|
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
perror(__FILE__ ": malloc");
|
perror(__FILE__ ": malloc");
|
||||||
return 2;
|
return 2;
|
||||||
@@ -503,8 +487,17 @@ int main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n_args = (cur - args);
|
||||||
|
if ((n_args + argc) > DEFAULT_MAX_ARGS) {
|
||||||
|
args = realloc(args, (n_args + argc) * sizeof(char *));
|
||||||
|
if (args == NULL) {
|
||||||
|
perror(__FILE__ ": realloc");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* append forward args and terminating NULL */
|
/* append forward args and terminating NULL */
|
||||||
memcpy(cur, &argv[1], sizeof(char *) * argc);
|
memcpy(&args[n_args], &argv[1], sizeof(char *) * argc);
|
||||||
|
|
||||||
exec_args = args;
|
exec_args = args;
|
||||||
#ifdef BR_CCACHE
|
#ifdef BR_CCACHE
|
||||||
|
|||||||
Reference in New Issue
Block a user