mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-18 08:38:10 +08:00
Prevent the --keep-global-symbol and --globalize-symbol options from being used together.
This is the result of an email thread starting here: https://sourceware.org/ml/binutils/2018-09/msg00031.html The main point of the thread is this observation: * Supposing we had an object file with two globals, SomeGlobal and SomeOtherGlobal, if one were to do "--globalize-symbol SomeGlobal --keep-global-symbol SomeOtherGlobal", you might expect that both SomeGlobal and SomeOtherGlobal are global in the output file... but it isn't. Because --keep-global-symbol is set and doesn't include SomeGlobal, SomeGlobal will be demoted to a local symbol. And because the check to see if we should apply the --globalize-symbol flag checks "flags" (the original flag set), and not "sym->flags", it decides not to do anything, so SomeGlobal remains a local symbol. Although this is a weird edge case, should this be changed so that --keep-global-symbol implicitly keeps anything also specified via --globalize-symbol? (The code seems technically correct with respect to the documentation, but IMO the behavior is counter-intuitive). binutils* objcopy.c (copy_main): Issue a fata error if the --keep-global-symbol(s) and the --globalize-symbol(s) options are used together. * doc/binutils.texi: Document that the two options are incompatible. * testsuite/binutils-all/copy-5.d: New test. * testsuite/binutils-all/objcopy.exp: Run the new test.
This commit is contained in:
@ -4753,6 +4753,8 @@ copy_main (int argc, char *argv[])
|
||||
bfd_boolean show_version = FALSE;
|
||||
bfd_boolean change_warn = TRUE;
|
||||
bfd_boolean formats_info = FALSE;
|
||||
bfd_boolean use_globalize = FALSE;
|
||||
bfd_boolean use_keep_global = FALSE;
|
||||
int c;
|
||||
struct stat statbuf;
|
||||
const bfd_arch_info_type *input_arch = NULL;
|
||||
@ -4871,10 +4873,12 @@ copy_main (int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case OPTION_GLOBALIZE_SYMBOL:
|
||||
use_globalize = TRUE;
|
||||
add_specific_symbol (optarg, globalize_specific_htab);
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
use_keep_global = TRUE;
|
||||
add_specific_symbol (optarg, keepglobal_specific_htab);
|
||||
break;
|
||||
|
||||
@ -5306,11 +5310,13 @@ copy_main (int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case OPTION_GLOBALIZE_SYMBOLS:
|
||||
use_globalize = TRUE;
|
||||
add_specific_symbols (optarg, globalize_specific_htab,
|
||||
&globalize_specific_buffer);
|
||||
break;
|
||||
|
||||
case OPTION_KEEPGLOBAL_SYMBOLS:
|
||||
use_keep_global = TRUE;
|
||||
add_specific_symbols (optarg, keepglobal_specific_htab,
|
||||
&keepglobal_specific_buffer);
|
||||
break;
|
||||
@ -5446,6 +5452,9 @@ copy_main (int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (use_globalize && use_keep_global)
|
||||
fatal(_("--globalize-symbol(s) is incompatible with -G/--keep-global-symbol(s)"));
|
||||
|
||||
if (formats_info)
|
||||
{
|
||||
display_info ();
|
||||
|
Reference in New Issue
Block a user