Von: Grant Edwards
Gesendet am: 22 Jun 2010 16:16:20
>> segments -> = sections. I think I got the 'empty' by browsing the ld
>> option description. Or i dedutcted it from your expression of
>> discarded unused content.
> unused != empty
right. Well, when all content has been discarded because being unused, it is
empty. :)
>>> Second, it's '--gc-sections' not '-gc-sections'
>> I tried both :)
>And both would have produced an error/warning using your posted
>makefile, which should have prompted you to try figure out what you
>were doing wrong rather than claiming the feature didn't work:
I never got one. In theory, my frontend should capture stdout and stderr.
And normally I see any output from compiler and/or linker.
So I never thought that I was missing the -Wl prefix.
I just tried agian with intentionally requesting an error message, yet there
was none.
Then I tried to call make from the windows 'DOS' console. Still no error
message.
Is it possible that it is pushed into an output streamthat is swallowed by the
windows
environment? Unlinkely, I know, as other warnings/errors come through
>> That's the point. (or nearly, according to the GC manual, it is -Wl,x
>> (which works)
> Right. Sorry about the typo.
No problem, now that I was pointed into the right direction.
>> I read the ld documentation and missted the fact that the compiler
>> gets the options first, even if added to LDFLAGS.
> The ld documentation has no way of knowing what program you're passing
> LDFLAGS to in your Makefile.
Now that I remember that ld is called through gcc, it's obvious.
Most of the makefile setup was inherited from my predecessor and I
guess he got most of it from the mspgcc templates.
>> Nevertheless, I don't understand why foo() is added to the binary by
>> the linker default, while it is not referenced and in its own object
>> file.
> Because you didn't pass the --gc-sections flag to the linker to tell
> it to discard unreferenced sections.
let me rearrange the statement:
I don't understand why the -gc-sections flag is needed to activate
a functionality I consider the default behaviour of a linker.
I would understand that you'll need to tell the linker that
you want to _keep_ unreferenced information, but not that it will
by default keep everything (at least for object files and even
completely unreferenced object files) while it does discard
unused parts from a library.
Maybe that is why my predecessor put all object files into a library
and linked it, so unreferenced object files didn't get linked,
while introducing that maybe even (later) referenced code wasn't linked.
When I took over the projects, I had no way to ask him as he left
the company.
>> Since 1) is the default, binary files may be unnecessary large by
>> default.
> Yes.
And that's what I don't understand: why is the special case (keep it
even if not referenced and therefore unreachable) is the default and the
default case (keep only what's used) requires extra treatment.
Anyway, now that I know that it is so, I can live with it.
So while I'm sorry alarming you unnecessarily, I'm quite happy that
I did, as I gained some valuable insights from this discussion.
And maybe others did too.
After all this is a compiler users mailing list and not a
compiler programmers list. :)
JMGross