when is ld appending .number to end of section names?

Sam Ravnborg sam@ravnborg.org
Tue Jan 22 15:54:00 GMT 2008


Hi Mike.

> >
> > See: http://lkml.org/lkml/2008/1/19/51
> 
> seems to me the code should be using the already existing macros ...
> 
> > Having started to look into this I tried to dig a bit more into the
> > subject of sections and assembler code.
> >
> > In the kernel we have following ways to specify the .init.text section:
> > a) .section .init.text, "ax"
> > b) .section ".init.text", "ax"
> > c) .section ".init.text", #alloc, #execinstr
> > d) .section .init.text, "ax", @progbits
> 
> e) use the macros in linux/init.h:
> __INIT
> <stuff>
> __FINIT

Background for my question was actually to be able to define cross
architecture definitions for sections to be used in assembler files.
So I was aware of __INIT but had overlooked __FINIT.

I now looked up the exact semantic of .previous and I see that 
I could have replaced the .pushsection/.popsection with a
pair of .section/.previous (__INIT/__FINIT).

I will submit an updated patch - thanks.

> > It is my understanding that a) b) and c) are equal.
> > And the preferred syntax is a) (I would prefer c) as it is more
> > descriptive)
> 
> yes
> 
> > The syntax in d) is used in some places.
> > What is the significance of specifying @progbits?
> 
> sets the proper TYPE on the ELF section so that when things get merged, only 
> alike things get merged.  also used by debuggers/ldso/elf parsers as a hint 
> at how to treat the data in the section (or whether to just completely ignore 
> the section)
> 
> > The main reason I bring up this question is that I cannot create
> > a macro like this:
> > #define __INIT .section .init.text, "ax", @progbits
> >
> > as it would fail on ARM where '@' is used to specify a comment.
> 
> use %progbits in include/linux/init.h then
> 
> > So the simplest solution would be to just drop "@progbits",
> > but before that I would like to understand the usage.
> >
> > An explanation of the use of "@progbits" would be good - but
> > a pointer to some documentation would be preferred as I then can
> > read up on this instead of asking.
> >
> > info gas told me this:
> >
> > `@progbits'
> >      section contains data
> >
> > `@nobits'
> >      section does not contain data (i.e., section only occupies space)
> >
> > But that did not convince me that the use of "@progbits" was optional and
> > could be dropped.
> 
> i think gas is smart enough to guess the proper section type, but if you want 
> to be explicit/correct, then you should specify it

I could read this in info gas:
----
  Note on targets where the `@' character is the start of a comment (eg
ARM) then another character is used instead.  For example the ARM port
uses the `%' character.
----

>From this I cannot read that '%' is documented as a valid replacement for '@'.
And relying on undocumented behaviour is no good.

A quick test with my i386 toolchain says it works for me.
ld --ver: 2.15

So I will cook up a patch that uses '%' - but I need to prepare some other stuff first.

	Sam



More information about the Binutils mailing list