binutils ld 2-32, defined in discarded section error

pierre willard pierre@willard.com
Thu Feb 14 03:20:00 GMT 2019


Thanks for the answer. I am probably using a bad ld script file. My goal is
to take a (big) object file, and create another (relocatable) object file
with a bunch of sections removed.
Basically I do : ld -r -o outputfile.o -Tscriptfile inputfile.o
If my script file has a just a bunch of /DISCARD/  (nothing else) this
command works (no error, sections are removed), but later on, when trying
to use this outputfile.o, it says :  file not recognized: Bad value.
If my script file has the original script (as per ld -r --verbose) with the
added /DISCARD/ commands at the very end of that script, then this command
fails with some symbol referenced in discarded section.
I guess there is no simple way to cleanly remove a section, while keeping
the current file format. Right? (I tried objcopy -R option, but it does not
remove related information, eg, relocation references).
regards
Pierre

On Wed, Feb 13, 2019 at 3:56 PM Alan Modra <amodra@gmail.com> wrote:

> On Wed, Feb 13, 2019 at 01:47:54PM -0800, pierre willard wrote:
> > Hello,
> > I am using ld + /DISCARD/ script to remove some sections from a big
> object
> > file, and I get this kind of error:
> >
> >
> `.text._ZN5boost16exception_detail12refcount_ptrINS0_20error_info_containerEE7add_refEv.isra.22'
> > referenced in section
> >
> `.text._ZN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEC2ERKS3_[_ZN5boost16exception_detail19error_info_injectorINS_17bad_function_callEEC5ERKS3_]'
> > of myLib.ooo: defined in discarded section
> >
> `.text._ZN5boost16exception_detail12refcount_ptrINS0_20error_info_containerEE7add_refEv.isra.22'
> > of myLib.ooo
> >
> > It is correct that  the section where this symbol is defined is being
> > discarded.
> > But the weird thing is that the section where this symbol is referenced
> is
> > also being discarded, so it seems ld should not be complaining.
> > is this correct?
>
> Are you certain the referencing section is being discarded?  I very
> much doubt that it is.
>
> --
> Alan Modra
> Australia Development Lab, IBM
>



More information about the Binutils mailing list