bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Overloading ld linker script is not working after 2_36


From: Phil Wiggum
Subject: Re: Overloading ld linker script is not working after 2_36
Date: Wed, 15 Feb 2023 10:28:36 +0100


> Sent: Wednesday, February 15, 2023 at 3:23 AM
> From: "Alan Modra" <amodra@gmail.com>
> To: "Phil Wiggum" <p1mail2015@mail.com>
> Cc: bug-binutils@gnu.org
> Subject: Re: Overloading ld linker script is not working after 2_36
>
> On Tue, Feb 14, 2023 at 07:54:29PM +0100, Phil Wiggum wrote:
> > I can't get NOLOAD working any more.
> > This used to work before binutils_2_36.
> >
> > Default linker script 'cc430f5137.ld' is overloaded with a script file 
> > (without -T)
> >
> > SECTIONS
> > {
> >   .infoA  (NOLOAD)   : {} > INFOA
> >   .infoB  (NOLOAD)   : {} > INFOB
> >   .infoC  (NOLOAD)   : {} > INFOC
> >   .infoD  (NOLOAD)   : {} > INFOD
> > }
> >
> > From ld man page:
> > If the linker cannot recognize the format of an object file, it
> > will assume that it is a linker script.  A script specified in
> > this way augments the main linker script used for the link
> > (either the default linker script or the one specified by using
> > -T).  This feature permits the linker to link against a file
> > which appears to be an object or an archive, but actually merely
> > defines some symbol values, or uses "INPUT" or "GROUP" to load
> > other objects.  Specifying a script in this way merely augments
> > the main linker script, with the extra commands placed after the
> > main script; use the -T option to replace the default linker
> > script entirely, but note the effect of the "INSERT" command.
> >
> > Default cc430f5137.ld...
> > ....
> >   .infoA     : {} > INFOA   /* MSP430 INFO FLASH MEMORY SEGMENTS */
> >   .infoB     : {} > INFOB
> >   .infoC     : {} > INFOC
> >   .infoD     : {} > INFOD
> > ....
> >
> > Modifying default script with NOLOAD works, but not if I try to overload it.
> >
> >
> > msp430-elf-gcc -Wl,--as-needed -Wl,--no-undefined -mmcu=cc430f5137 
> > -Wl,--start-group -Wl,--end-group -Wl,--verbose=255 
> > overload-ld/cc430f5137.ld -Wl,-gc-sections -Wl,-Map,cc430f5137.map main.o 
> > -o out
>
> I think you've been affected by a deliberate linker change in the
> handling of duplicate output sections.  What you'll end up with now
> when using your script is overall the same as a single script with
>
>   .infoA     : {} > INFOA
> ...
>   .infoA  (NOLOAD)   : {} > INFOA
>
> What that will do is put .infoA sections into the first .infoA output
> section seen (by the linker orphan section handling since the script
> doesn't have { *(.infoA) }.  This suggests two ways you can fix your
> extra linker script.
> 1) Write ".infoA (NOLOAD) : { *(.infoA) } > INFOA" and similarly for
> the other output sections in your extra script.  By specifying the
> input sections these will match your output section before orphan
> sections are handled.  This modification should work with older
> linkers too.
> 2) Add INSERT BEFORE .infoA; at the end of your extra script.
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

1st Way:

SECTIONS
{
  .infoA  (NOLOAD)   : { *(.infoA) } > INFOA
  .infoB  (NOLOAD)   : { *(.infoB) } > INFOB
  .infoC  (NOLOAD)   : { *(.infoC) } > INFOC
  .infoD  (NOLOAD)   : { *(.infoD) } > INFOD
}

Did work perfectly!!

2nd Way:

SECTIONS
{
  .infoA  (NOLOAD)   : {} > INFOA
  .infoB  (NOLOAD)   : {} > INFOB
  .infoC  (NOLOAD)   : {} > INFOC
  .infoD  (NOLOAD)   : {} > INFOD
} INSERT BEFORE .infoA

Did not work: bin/ld: .infoA not found for insert
bin/ld --version  -> 2.40.50.20230214

//Thanks :-)







reply via email to

[Prev in Thread] Current Thread [Next in Thread]