public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* .gnu.linkonce.? and .gcc_except_table
@ 2009-03-24 23:08 John Farmer
  2009-03-24 23:18 ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: John Farmer @ 2009-03-24 23:08 UTC (permalink / raw)
  To: gcc-help


Hi,

I have a linker script file that has been created automatically by the IDE
that I am using. There are just one or two commands which I do not
understand and love nor money appears to shed any light all over the
internet on the subject.

What pray tell may does .gnu.linkonce.r, .gnu.linkonce.b etc and
gcc_except_table all mean when applied to input sections? Are any of these
actually documented, presumably there are other such options too?

Perhaps there is a good book available on the ins and outs of linker scripts
or maybe a pdf hidden away in some dark corner. Any ideas?

One last question if I may. In my trawling about I came across the term SysV
in terms of linker scripts. What is this?

Regards John Farmer.
-- 
View this message in context: http://www.nabble.com/.gnu.linkonce.--and-.gcc_except_table-tp22691863p22691863.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: .gnu.linkonce.? and .gcc_except_table
  2009-03-24 23:08 .gnu.linkonce.? and .gcc_except_table John Farmer
@ 2009-03-24 23:18 ` Ian Lance Taylor
  2009-03-24 23:26   ` John Farmer
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2009-03-24 23:18 UTC (permalink / raw)
  To: John Farmer; +Cc: gcc-help

John Farmer <news02@lavabit.com> writes:

> What pray tell may does .gnu.linkonce.r, .gnu.linkonce.b etc and
> gcc_except_table all mean when applied to input sections? Are any of these
> actually documented, presumably there are other such options too?

Those are the names of input section names.  The names beginning with
.gnu.linkonce are used by gcc for vague linking.  See the docs in the
gcc manual for why vague linking exists.  When the GNU linker sees two
input sections with the same name, and the name starts with
".gnu.linkonce.", the linker will only keep one copy and discard the
other.  .gcc_except_table is also an input section name, which gcc uses
for information used to unwind the stack when an exception occurs.


> Perhaps there is a good book available on the ins and outs of linker scripts
> or maybe a pdf hidden away in some dark corner. Any ideas?

Unfortunately I don't know of anything better than the linker
documentation.  I wrote the docs on linker scripts--they aren't so great
now but you should have seen what they looked like before.


> One last question if I may. In my trawling about I came across the term SysV
> in terms of linker scripts. What is this?

The GNU ld linker script language was originally based on the linker
script language used in the SVR3 linker.  It's changed a lot since then,
though.  (At some point the GNU linker also got support for the MRI
linker script language, but it is not widely used.  I hope.)

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: .gnu.linkonce.? and .gcc_except_table
  2009-03-24 23:18 ` Ian Lance Taylor
@ 2009-03-24 23:26   ` John Farmer
  2009-03-26 18:27     ` John Farmer
  0 siblings, 1 reply; 9+ messages in thread
From: John Farmer @ 2009-03-24 23:26 UTC (permalink / raw)
  To: gcc-help


Well that's just about wrapped up my questions (for a while anyway).

You are a great help, cheers.

Regards John Farmer
-- 
View this message in context: http://www.nabble.com/.gnu.linkonce.--and-.gcc_except_table-tp22691863p22692103.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: .gnu.linkonce.? and .gcc_except_table
  2009-03-24 23:26   ` John Farmer
@ 2009-03-26 18:27     ` John Farmer
  2009-03-27 16:26       ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: John Farmer @ 2009-03-26 18:27 UTC (permalink / raw)
  To: gcc-help


Hi,

In my .text output section the input sections include .gnu.linkonce.t*
amongst others.

I understand that it is possible under some circumstances for one or more
sections to have the same name.

Is it possible to cause this to happen deliberately, just for my own
curiosity, from within a C program? If so how would it be done? If not
possible using C how about using C++.

When the linker sees two input sections with the same name are we saying
that it only ever keeps one copy or are we saying that only if it starts
with the special .gnu.linkonce. prefix is just one section kept?

Regards John Farmer
-- 
View this message in context: http://www.nabble.com/.gnu.linkonce.--and-.gcc_except_table-tp22691863p22728191.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: .gnu.linkonce.? and .gcc_except_table
  2009-03-26 18:27     ` John Farmer
@ 2009-03-27 16:26       ` Ian Lance Taylor
  2009-03-28  9:46         ` John Farmer
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2009-03-27 16:26 UTC (permalink / raw)
  To: John Farmer; +Cc: gcc-help

John Farmer <news02@lavabit.com> writes:

> In my .text output section the input sections include .gnu.linkonce.t*
> amongst others.
>
> I understand that it is possible under some circumstances for one or more
> sections to have the same name.
>
> Is it possible to cause this to happen deliberately, just for my own
> curiosity, from within a C program? If so how would it be done? If not
> possible using C how about using C++.

I'm not sure exactly what you are asking.  Are you asking how to have
more than one section with the same name?  I assume you mean across a
set of input files--it's unusual for a single input file to have
multiple input sections with the same name.  Across input files, it is
routine; for example, by default, all ordinary code will be put into the
.text section in each input file.

> When the linker sees two input sections with the same name are we saying
> that it only ever keeps one copy or are we saying that only if it starts
> with the special .gnu.linkonce. prefix is just one section kept?

Only if it starts with the special .gnu.linkonce. prefix.  Otherwise all
input sections with the same name are normally combined into an output
section with that name.

There is a lot of basic information about linkers in my blog entries
starting at http://airs.com/blog/archives/38 .

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: .gnu.linkonce.? and .gcc_except_table
  2009-03-27 16:26       ` Ian Lance Taylor
@ 2009-03-28  9:46         ` John Farmer
  2009-03-28 11:29           ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 9+ messages in thread
From: John Farmer @ 2009-03-28  9:46 UTC (permalink / raw)
  To: gcc-help


Hi Ian,

Yes my question was not particularly well worded. Basically I have two
problem areas.

The first is exactly what does .gnu.linkonce. mean and I think you have
answered that one for me already. This is my understanding please correct me
if I am wrong.

"Unlike other input section types a section that is prefixed with
.gni.linkonce. is treated differently by the linker. If for example
.gnu.linkonce.t.abc appears in two or more different object files then the
linker will only keep one and discard the others."

The second is to create an object file that contains a link once section in
it which can be verified with say objdump. So far my attempts to do this
have only resulted in .text sections being created.

Is there an example, perhaps, that will cause this illusive link once
section to appear in an object file? Do they actually appear in C programs?

Many thanks for your time.
Best regards John Farmer
-- 
View this message in context: http://www.nabble.com/.gnu.linkonce.--and-.gcc_except_table-tp22691863p22755182.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: .gnu.linkonce.? and .gcc_except_table
  2009-03-28  9:46         ` John Farmer
@ 2009-03-28 11:29           ` John (Eljay) Love-Jensen
  2009-03-28 15:07             ` John Farmer
  0 siblings, 1 reply; 9+ messages in thread
From: John (Eljay) Love-Jensen @ 2009-03-28 11:29 UTC (permalink / raw)
  To: John Farmer, gcc-help

Hi John,

The linkonce is to support C++ vague linkage.  It is related to C++'s ODR, and can cause surprises if ODR is violated.

> Is there an example, perhaps, that will cause this illusive link once section to appear in an object file?

If you compile with RTTI turned on, you'll see linkonce sections for all the RTTI of all the classes in the translation unit of that object file.

If you keep generated functions for inline functions (-fkeep-inline-functions), I presume you'll see linkonce sections for all the emitted kept inline functions.

(Since, typically, inline functions are in header files, this would be a violation of the principle that header files do not emit code (.text) or data (.data, .bss) into object files.  RTTI information emitted is fuzzy, and doesn't count against the principle.)

> Do they actually appear in C programs?

I am not aware of C programs using linkonce, since it's for linker support for C++ vague linkage semantics.

Perhaps used for C static inline functions in header files.  (C99)

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: .gnu.linkonce.? and .gcc_except_table
  2009-03-28 11:29           ` John (Eljay) Love-Jensen
@ 2009-03-28 15:07             ` John Farmer
  2009-03-28 15:43               ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: John Farmer @ 2009-03-28 15:07 UTC (permalink / raw)
  To: gcc-help


Hi,

Many thanks for that.

I switched on RTTI and did get some link once sections as shown in the
object file. They were not quite named the way I expected though. 

For example I coded in a C++ file a simple class, MyClass, that consisted of
just one constructor MyClass() defined inline.

In the object file I got.

_ZN7MyClassC1Ev which was shown as LINK_ONCE_DISCARD and also a
.text._ZN7MyClassC1Ev section.

I did not find any sections that used the prefix .gnu.linkonce.t., for
example I would have expected to see a section named
.gnu.linkonce.t._ZN7MyClassC1Ev

I am using V4.1.1 of the GCC toolset if that is significant.

Are these results as would be expected or should I have indeed got some
.gnu.linkonce.t. prefixed sections?

Regards John Farmer

-- 
View this message in context: http://www.nabble.com/.gnu.linkonce.--and-.gcc_except_table-tp22691863p22757792.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: .gnu.linkonce.? and .gcc_except_table
  2009-03-28 15:07             ` John Farmer
@ 2009-03-28 15:43               ` Ian Lance Taylor
  0 siblings, 0 replies; 9+ messages in thread
From: Ian Lance Taylor @ 2009-03-28 15:43 UTC (permalink / raw)
  To: John Farmer; +Cc: gcc-help

John Farmer <news02@lavabit.com> writes:

> I switched on RTTI and did get some link once sections as shown in the
> object file. They were not quite named the way I expected though. 
>
> For example I coded in a C++ file a simple class, MyClass, that consisted of
> just one constructor MyClass() defined inline.
>
> In the object file I got.
>
> _ZN7MyClassC1Ev which was shown as LINK_ONCE_DISCARD and also a
> .text._ZN7MyClassC1Ev section.
>
> I did not find any sections that used the prefix .gnu.linkonce.t., for
> example I would have expected to see a section named
> .gnu.linkonce.t._ZN7MyClassC1Ev
>
> I am using V4.1.1 of the GCC toolset if that is significant.
>
> Are these results as would be expected or should I have indeed got some
> .gnu.linkonce.t. prefixed sections?

If your GNU binutils are new enough, then gcc will use ELF section
groups instead of .gnu.linkonce sections.  objdump -h will report a
section group using "GROUP" in the list of flags.  .gnu.linkonce
sections were introduced back in the mid-90's; ELF section groups are a
newer, more flexible, approach.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-03-28 15:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-24 23:08 .gnu.linkonce.? and .gcc_except_table John Farmer
2009-03-24 23:18 ` Ian Lance Taylor
2009-03-24 23:26   ` John Farmer
2009-03-26 18:27     ` John Farmer
2009-03-27 16:26       ` Ian Lance Taylor
2009-03-28  9:46         ` John Farmer
2009-03-28 11:29           ` John (Eljay) Love-Jensen
2009-03-28 15:07             ` John Farmer
2009-03-28 15:43               ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).