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]

objcopy --localize-symbol / --weaken-symbol (and friends)


I have recently been looking at the --localize-symbol option in
objcopy, though the following points are also true for all of the
objcopy options that deal with symbols, and also for the strip tools
keep-symbol and strip-symbol options (I believe).

When using the '--wildcard' option with objcopy to activate regexp
matching in the symbol name, the following comment appears in the
manual page for objcopy:

	For example:

		-w -W !foo -W fo*

	would cause objcopy to weaken all symbols that start with "fo"
	except for the symbol "foo".

However, using the following input file (test.s):

	        .global foo, foa, fob
	        .global bar, baa, bab
	        .data
	foo: foa: fob:
	bar: baa: bab:
	        .word 0x0

Then test as:

	as -o test.o test.s
	objcopy --wildcard \
	        --weaken-symbol='!foo' \
	        --weaken-symbol='fo*' test.o
	objdump --syms test.o

Shows that the manual page is wrong, and all symbols are weakened.

The '--wildcard' feature was added in commit 5fe1184, I went back and
tested at that commit, and I don't think that this feature ever worked
as advertised.

So my first question would be, is this user error?  Am I misreading
the manual, or misusing the command line flags?

So, if we assume for now I'm reading things right then we could change
the manual to document the current behaviour, this is good in that
anyone relying on the current behaviour will not be upset.

However, I think that the behaviour described in the manual is better
than the current behaviour, and I'd like to move the tools towards
matching the manual.  Before I start any work though I'm looking for
some buy-in.

The reason that I think the manual behaviour is better can be seen
when using the example source file I gave above.  What if the user
wants to weaken all symbols except for 'foo' and 'bar'?  Using the
manual I would expect that this should work:

	objcopy -w -W '!foo' -W '!bar' -W '*'

However, this currently does not work, the '!foo' matches all symbols
that don't match the pattern 'foo', while '!bar' matches all symbols
not matching the pattern 'bar', at which point we've covered all
symbols, including 'foo' and 'bar'.

My proposal (without yet looking at an implementation) would be that
the patterns match in left to right order, and that a symbol will only
be matched once.  So, in the above, '!foo' will match 'foo', and
(internally) mark the symbol with DO-NOT-WEAKEN, '!bar' would match
'bar', and again mark DO-NOT-WEAKEN, while the final '*' would match
all of the _remaining_ symbols, and mark 'WEAKEN'.  At this point all
of the symbols actions WEAKEN or DO-NOT-WEAKEN would be applied.

There's some details about how to handle mixing of weaken, localize,
and globalize that I have not yet figured out.

If I posted patches relating to the above would anyone object?

Does anyone have an alternative suggestion?

Thanks,
Andrew


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]