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

2023-02-15 Thread Phil Wiggum



> Sent: Wednesday, February 15, 2023 at 3:23 AM
> From: "Alan Modra" 
> To: "Phil Wiggum" 
> 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 :-)







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

2023-02-15 Thread Nick Clifton

Hi Phil,


I can't get NOLOAD working any more.
This used to work before binutils_2_36.


The behaviour of the 2.36 binutils may have been accidental rather than 
intended...

The key thing here is that input source files that are actually linker
script fragments are interpreted as augmenting the *end* of the default
linker script, rather than the start.  So even though your fragment file
contains:


   .infoA  (NOLOAD)   : {} > INFOA


The default script contains:


   .infoA : {} > INFOA   /* MSP430 INFO FLASH MEMORY SEGMENTS */


And this is interpreted first.  Hence the sections do not gain the NOLOAD
attribute.

The best way to solve this issue is to just override the default linker
script with your own version using the -T command line option.

If that is not feasible then the only other solution that I can think of
is to rename the .infoA sections (using objcopy's --rename-section command
line option) to something else, eg .renamed.infoA, as a pre-link step
and then use your script fragment to assign the renamed sections, eg:

  .renamed.infoA (NOLOAD) : { *(.renamed.infoA) } > INFOA

Cheers
  Nick




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

2023-02-14 Thread Alan Modra
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



Overloading ld linker script is not working after 2_36

2023-02-14 Thread Phil Wiggum
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


//Phil



cc430f5137.ld
Description: Binary data