This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
As part of work on LLVM binutils, I've been spending time looking at GNU objcopy. One thing I'm confused by is how --globalize-symbol and --keep-global-symbol are supposed to work, especially when comparing their documented effects vs reading the code. My understanding from documentation is that --globalize-symbol is supposed to promote a symbol to global visibility, and --keep-global-symbol is supposed to localize all symbols except those retained by --keep-global-symbol. However, the way it's written (simplified for purposes of this thread) looks like this: for (symbol *sym : symbols) { flagword flags = sym->flags; char* name = sym->name; // If flag is global/weak, and --keep-global-symbol includes it, // make it local if ((flags & (GLOBAL | WEAK)) && (keep_globals.size() != 0 && !list_contains(keep_globals, name))) { sym->flags &= ~(GLOBAL | WEAK); sym->flags |= LOCAL; } // If flag is local and --globalize-symbol is set, make it global // Note: checks flags, not sym->flags if ((flags & LOCAL) && list_contains(globalize, name)) { sym->flags &= ~LOCAL; sym->flags |= GLOBAL; } } The actual snippet I'm talking about is here: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/objcopy.c;h=6bd933993b39e9f4d3038d3045a1d4096705be3e;hb=HEAD#l1627 The two things I'd like to ask about this: * Weak symbols are not globalized. --help/man pages never mention this. Is this intentional? * 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). Note that I haven't (yet) seen anyone actually try to use objcopy in either of these ways, this is just something I've noticed from reading documentation and code. I'm wondering if this behavior is intentional, and if anyone is known to be relying on objcopy working this way. Thanks -- Jordan
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |