Discussion:
KEEP sections without writing a complete linker script?
Lars Noschinski
2010-06-17 13:15:11 UTC
Permalink
Hi,

is there a way to explicitely KEEP a section without needing to write a
whole new linker file?

It seemed to me that using a script which is appended to the default
script is a way to go, so I wrote the following script:

| SECTIONS
| {
| .bootcall_trampoline :
| {
| *(.bootcall_trampoline)
| KEEP(*(.bootcall_trampoline))
| }
| }

This seems to work, but gives me the annoying warning

| /usr/lib/gcc/avr/4.3.4/../../../avr/bin/ld: warning: keep_bootcall.x contains output sections; did you forget -T?

So I have got two questions:

- Is my approach correct?
- If yes, can this warning be suppressed?

Greetings,
Lars Noschinski
Tristan Gingold
2010-06-17 13:28:56 UTC
Permalink
Post by Lars Noschinski
Hi,
is there a way to explicitely KEEP a section without needing to write a
whole new linker file?
It seemed to me that using a script which is appended to the default
| SECTIONS
| {
| {
| *(.bootcall_trampoline)
| KEEP(*(.bootcall_trampoline))
| }
| }
This seems to work, but gives me the annoying warning
| /usr/lib/gcc/avr/4.3.4/../../../avr/bin/ld: warning: keep_bootcall.x contains output sections; did you forget -T?
- Is my approach correct?
- If yes, can this warning be suppressed?
Let me try to answer:

How did you invoke gcc or ld ? It seems, according to the error message, that you forget the -T switch. Ie, you
should use something like -Wl,-T,myscript.ld

Your script looks strange: you shouldn't repeat the input section. I think that written as is the second line has no effect.
You should use something like:
SECTIONS
{
.bootcall_trampoline :
{
KEEP(*(.bootcall_trampoline))
}
}

Tristan.
Tristan Gingold
2010-06-17 16:12:14 UTC
Permalink
Post by Tristan Gingold
Post by Lars Noschinski
| SECTIONS
| {
| {
| *(.bootcall_trampoline)
| KEEP(*(.bootcall_trampoline))
| }
| }
This seems to work, but gives me the annoying warning
| /usr/lib/gcc/avr/4.3.4/../../../avr/bin/ld: warning: keep_bootcall.x contains output sections; did you forget -T?
[...]
Post by Tristan Gingold
How did you invoke gcc or ld ? It seems, according to the error message, that you forget the -T switch. Ie, you
should use something like -Wl,-T,myscript.ld
Using -T would give me not the effect I wanted, as this would replace
the default linker script.
Ok, you can use -Wl,-dT,-T,myscript.ld to also read the default linker script.

Tristan.
Lars Noschinski
2010-06-17 17:54:39 UTC
Permalink
Post by Tristan Gingold
Post by Tristan Gingold
Post by Lars Noschinski
| /usr/lib/gcc/avr/4.3.4/../../../avr/bin/ld: warning: keep_bootcall.x contains output sections; did you forget -T?
[...]
Post by Tristan Gingold
How did you invoke gcc or ld ? It seems, according to the error message, that you forget the -T switch. Ie, you
should use something like -Wl,-T,myscript.ld
Using -T would give me not the effect I wanted, as this would replace
the default linker script.
Ok, you can use -Wl,-dT,-T,myscript.ld to also read the default linker script.
This won't work either, as -dT also expects a file name as parameter.

But after re-reading the documentation, if found that the INSERT command
does exactly what I want:

Using the script

| SECTIONS
| {
| .bootcall_trampoline :
| {
| KEEP(*(.bootcall_trampoline))
| }
| }
| INSERT AFTER .text

I may call the linker with "-T myscript.ld" and everything works as
expected.

Sorry for the noise,
Lars Noschinski
Tristan Gingold
2010-06-18 07:56:03 UTC
Permalink
Post by Lars Noschinski
Post by Tristan Gingold
Post by Tristan Gingold
Post by Lars Noschinski
| /usr/lib/gcc/avr/4.3.4/../../../avr/bin/ld: warning: keep_bootcall.x contains output sections; did you forget -T?
[...]
Post by Tristan Gingold
How did you invoke gcc or ld ? It seems, according to the error message, that you forget the -T switch. Ie, you
should use something like -Wl,-T,myscript.ld
Using -T would give me not the effect I wanted, as this would replace
the default linker script.
Ok, you can use -Wl,-dT,-T,myscript.ld to also read the default linker script.
This won't work either, as -dT also expects a file name as parameter.
Yes, sorry.
Post by Lars Noschinski
But after re-reading the documentation, if found that the INSERT command
Using the script
| SECTIONS
| {
| {
| KEEP(*(.bootcall_trampoline))
| }
| }
| INSERT AFTER .text
I may call the linker with "-T myscript.ld" and everything works as
expected.
Right, this seems indeed to be the best method.

Tristan.
Dave Korn
2010-06-18 14:13:02 UTC
Permalink
Post by Tristan Gingold
Post by Lars Noschinski
But after re-reading the documentation, if found that the INSERT command
Using the script
| SECTIONS
| {
| {
| KEEP(*(.bootcall_trampoline))
| }
| }
| INSERT AFTER .text
I may call the linker with "-T myscript.ld" and everything works as
expected.
Right, this seems indeed to be the best method.
You guys are making my head hurt! How is that supposed to work, when -T
"replaces `ld''s default linker script (rather than adding to it)"? What is
there to INSERT AFTER if you use -T?

As far as I understand you don't want to use any option at all. Just pass
the name of the script fragment on the command-line (regardless whether passed
via gcc or invoking ld directly) and it gets appended to the default script.

cheers,
DaveK
Tristan Gingold
2010-06-18 14:42:50 UTC
Permalink
Post by Dave Korn
You guys are making my head hurt! How is that supposed to work, when -T
"replaces `ld''s default linker script (rather than adding to it)"? What is
there to INSERT AFTER if you use -T?
See the documentation:

INSERT [ AFTER | BEFORE ] output_section
This command is typically used in a script specified by `-T' to augment the default SECTIONS with, for example, overlays. It inserts all prior linker script statements after (or before) output_section, and also causes `-T' to not override the default linker script.
Post by Dave Korn
As far as I understand you don't want to use any option at all. Just pass
the name of the script fragment on the command-line (regardless whether passed
via gcc or invoking ld directly) and it gets appended to the default script.
cheers,
DaveK
Dave Korn
2010-06-18 15:19:35 UTC
Permalink
Post by Tristan Gingold
Post by Dave Korn
You guys are making my head hurt! How is that supposed to work, when -T
"replaces `ld''s default linker script (rather than adding to it)"? What is
there to INSERT AFTER if you use -T?
INSERT [ AFTER | BEFORE ] output_section
This command is typically used in a script specified by `-T' to augment the default SECTIONS with, for example, overlays. It inserts all prior linker script statements after (or before) output_section, and also causes `-T' to not override the default linker script.
Boh! Maybe the -T documentation should mention something about that too.

cheers,
DaveK
Tristan Gingold
2010-06-18 15:04:49 UTC
Permalink
Post by Dave Korn
Post by Tristan Gingold
Post by Dave Korn
You guys are making my head hurt! How is that supposed to work, when -T
"replaces `ld''s default linker script (rather than adding to it)"? What is
there to INSERT AFTER if you use -T?
INSERT [ AFTER | BEFORE ] output_section
This command is typically used in a script specified by `-T' to augment the default SECTIONS with, for example, overlays. It inserts all prior linker script statements after (or before) output_section, and also causes `-T' to not override the default linker script.
Boh! Maybe the -T documentation should mention something about that too.
Yes, this will make things clearer. Feel free to submit a patch :-)

Tristan.

Lars Noschinski
2010-06-17 16:01:54 UTC
Permalink
Post by Tristan Gingold
Post by Lars Noschinski
| SECTIONS
| {
| {
| *(.bootcall_trampoline)
| KEEP(*(.bootcall_trampoline))
| }
| }
This seems to work, but gives me the annoying warning
| /usr/lib/gcc/avr/4.3.4/../../../avr/bin/ld: warning: keep_bootcall.x contains output sections; did you forget -T?
[...]
Post by Tristan Gingold
How did you invoke gcc or ld ? It seems, according to the error message, that you forget the -T switch. Ie, you
should use something like -Wl,-T,myscript.ld
Using -T would give me not the effect I wanted, as this would replace
the default linker script.
Post by Tristan Gingold
Your script looks strange: you shouldn't repeat the input section. I think that written as is the second line has no effect.
SECTIONS
{
{
KEEP(*(.bootcall_trampoline))
}
}
This might be better, I just followed the example in the default avr
linker scripts. Both variants produce the desired effect
(.bootcall_trampoline is not discarded).


Greetings,
Lars Noschinski
Loading...