public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Multiple sections with same name don't work
@ 2004-04-30 22:31 H. J. Lu
       [not found] ` <20040430230129.GA17907@lucon.org>
  0 siblings, 1 reply; 15+ messages in thread
From: H. J. Lu @ 2004-04-30 22:31 UTC (permalink / raw)
  To: binutils

The current assembler still doesn't support multiple section with
the same section name:

[hjl@gnu comdat-1]$ cat foo.s
        .text
.L1:
        .align 4
.L2:
.L3:
        .section        .data,"",@progbits
        .long   .L3-.L1
        .section        .text,"axG",@progbits,foo,comdat
[hjl@gnu comdat-1]$ gcc -c foo.s
foo.s: Assembler messages:
foo.s:7: Error: can't resolve `.text' {.text section} - `.L1' {.text section}


H.J.

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

* Re: PATCH: Multiple sections with same name don't work
       [not found] ` <20040430230129.GA17907@lucon.org>
@ 2004-05-01  0:36   ` H. J. Lu
  2004-05-01  2:31     ` Alan Modra
  0 siblings, 1 reply; 15+ messages in thread
From: H. J. Lu @ 2004-05-01  0:36 UTC (permalink / raw)
  To: binutils

On Fri, Apr 30, 2004 at 04:01:29PM -0700, H. J. Lu wrote:
> On Fri, Apr 30, 2004 at 03:12:44PM -0700, H. J. Lu wrote:
> > The current assembler still doesn't support multiple section with
> > the same section name:
> > 
> > [hjl@gnu comdat-1]$ cat foo.s
> >         .text
> > .L1:
> >         .align 4
> > .L2:
> > .L3:
> >         .section        .data,"",@progbits
> >         .long   .L3-.L1
> >         .section        .text,"axG",@progbits,foo,comdat
> > [hjl@gnu comdat-1]$ gcc -c foo.s
> > foo.s: Assembler messages:
> > foo.s:7: Error: can't resolve `.text' {.text section} - `.L1' {.text section}
> > 
> > 
> 
> This patch seems to work for me. I don't quite understand why we call
> symbol_set_bfdsym here if we only want to add the symbol to the
> symbol table.
> 
> 

It is not enough. Now I got

[hjl@gnu-psc comdat-2]$ gcc -c bar.s
bar.s: Assembler messages:
bar.s:14: Error: can't resolve `.text' {.text section} - `.LFB359' {.text
section}
[hjl@gnu-psc comdat-2]$ cat bar.s
        .section        .text,"axG",@progbits,foo,comdat
.LFB359:
.L46:
        jbe     .L46
.LFE359:
        .section        .text,"axG",@progbits,bar,comdat
.LFB401:
.L514:
        jmp     .L514
.LFE401:
        .section        .eh_frame,"a",@progbits
.Lframe1:
.LSCIE1:
        .long   .LFE359-.LFB359
.LASFDE101:
        .long   .LFE401-.LFB401
.LEFDE101:
        .section        .data,"awG",@progbits,foobar,comdat


H.J.

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  0:36   ` PATCH: " H. J. Lu
@ 2004-05-01  2:31     ` Alan Modra
  2004-05-01  2:59       ` Alan Modra
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Modra @ 2004-05-01  2:31 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Fri, Apr 30, 2004 at 05:36:37PM -0700, H. J. Lu wrote:
> bar.s:14: Error: can't resolve `.text' {.text section} - `.LFB359' {.text
> section}

I expect you need to rewrite all the parts of gas dealing with section
symbols.  :-(  The assumption is that global symbols have unique names,
which is no longer true.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  2:31     ` Alan Modra
@ 2004-05-01  2:59       ` Alan Modra
  2004-05-01  3:43         ` H. J. Lu
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Modra @ 2004-05-01  2:59 UTC (permalink / raw)
  To: H. J. Lu, binutils

On Sat, May 01, 2004 at 12:01:36PM +0930, Alan Modra wrote:
> On Fri, Apr 30, 2004 at 05:36:37PM -0700, H. J. Lu wrote:
> > bar.s:14: Error: can't resolve `.text' {.text section} - `.LFB359' {.text
> > section}
> 
> I expect you need to rewrite all the parts of gas dealing with section
> symbols.  :-(  The assumption is that global symbols have unique names,
> which is no longer true.

Actually, it is probably a mistake to try to support multiple sections
of the same name in gas.  For instance, if you have two .text sections,
how is gas supposed to evaluate ".long .text" ?

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  2:59       ` Alan Modra
@ 2004-05-01  3:43         ` H. J. Lu
  2004-05-01  4:25           ` Alan Modra
  0 siblings, 1 reply; 15+ messages in thread
From: H. J. Lu @ 2004-05-01  3:43 UTC (permalink / raw)
  To: H. J. Lu, binutils

On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
> On Sat, May 01, 2004 at 12:01:36PM +0930, Alan Modra wrote:
> > On Fri, Apr 30, 2004 at 05:36:37PM -0700, H. J. Lu wrote:
> > > bar.s:14: Error: can't resolve `.text' {.text section} - `.LFB359' {.text
> > > section}
> > 
> > I expect you need to rewrite all the parts of gas dealing with section
> > symbols.  :-(  The assumption is that global symbols have unique names,
> > which is no longer true.
> 
> Actually, it is probably a mistake to try to support multiple sections
> of the same name in gas.  For instance, if you have two .text sections,
> how is gas supposed to evaluate ".long .text" ?
> 

Will that be generated by compiler? If not, we can issue an error.


H.J.

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  3:43         ` H. J. Lu
@ 2004-05-01  4:25           ` Alan Modra
  2004-05-01  4:34             ` H. J. Lu
  2004-05-01  5:12             ` Zack Weinberg
  0 siblings, 2 replies; 15+ messages in thread
From: Alan Modra @ 2004-05-01  4:25 UTC (permalink / raw)
  To: H. J. Lu; +Cc: H. J. Lu, binutils

On Fri, Apr 30, 2004 at 08:43:00PM -0700, H. J. Lu wrote:
> On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
> > Actually, it is probably a mistake to try to support multiple sections
> > of the same name in gas.  For instance, if you have two .text sections,
> > how is gas supposed to evaluate ".long .text" ?
> 
> Will that be generated by compiler? If not, we can issue an error.

The real question is: Do we need multiple sections of the same name
in assembly files?  I don't think we do.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  4:25           ` Alan Modra
@ 2004-05-01  4:34             ` H. J. Lu
  2004-05-01  5:12             ` Zack Weinberg
  1 sibling, 0 replies; 15+ messages in thread
From: H. J. Lu @ 2004-05-01  4:34 UTC (permalink / raw)
  To: binutils

On Sat, May 01, 2004 at 01:55:06PM +0930, Alan Modra wrote:
> On Fri, Apr 30, 2004 at 08:43:00PM -0700, H. J. Lu wrote:
> > On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
> > > Actually, it is probably a mistake to try to support multiple sections
> > > of the same name in gas.  For instance, if you have two .text sections,
> > > how is gas supposed to evaluate ".long .text" ?
> > 
> > Will that be generated by compiler? If not, we can issue an error.
> 
> The real question is: Do we need multiple sections of the same name
> in assembly files?  I don't think we do.

The input file may not. But the output should. Otherwise, we have to
change the linker to support section group since it has

  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }



H.J.

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  4:25           ` Alan Modra
  2004-05-01  4:34             ` H. J. Lu
@ 2004-05-01  5:12             ` Zack Weinberg
  2004-05-01  5:50               ` H. J. Lu
  2004-05-01  7:08               ` H. J. Lu
  1 sibling, 2 replies; 15+ messages in thread
From: Zack Weinberg @ 2004-05-01  5:12 UTC (permalink / raw)
  To: H. J. Lu; +Cc: H. J. Lu, binutils

Alan Modra <amodra@bigpond.net.au> writes:

> On Fri, Apr 30, 2004 at 08:43:00PM -0700, H. J. Lu wrote:
>> On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
>> > Actually, it is probably a mistake to try to support multiple sections
>> > of the same name in gas.  For instance, if you have two .text sections,
>> > how is gas supposed to evaluate ".long .text" ?
>> 
>> Will that be generated by compiler? If not, we can issue an error.
>
> The real question is: Do we need multiple sections of the same name
> in assembly files?  I don't think we do.

I need them in order to generate COMDAT sections compatible with the
HPUX linker.  gcc might emit e.g.

     .section .text 
     # non-COMDAT code  ...

     .section .text,"G",symbol_name,comdat
     # code for symbol_name ...

     .section .eh_frame
     # non-COMDAT unwind info ...

     .section .eh_frame,"G",symbol_name,comdat
     # unwind info for symbol_name ...

zw

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  5:12             ` Zack Weinberg
@ 2004-05-01  5:50               ` H. J. Lu
  2004-05-01  7:06                 ` H. J. Lu
  2004-05-01  7:08               ` H. J. Lu
  1 sibling, 1 reply; 15+ messages in thread
From: H. J. Lu @ 2004-05-01  5:50 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1095 bytes --]

On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> Alan Modra <amodra@bigpond.net.au> writes:
> 
> > On Fri, Apr 30, 2004 at 08:43:00PM -0700, H. J. Lu wrote:
> >> On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
> >> > Actually, it is probably a mistake to try to support multiple sections
> >> > of the same name in gas.  For instance, if you have two .text sections,
> >> > how is gas supposed to evaluate ".long .text" ?
> >> 
> >> Will that be generated by compiler? If not, we can issue an error.
> >
> > The real question is: Do we need multiple sections of the same name
> > in assembly files?  I don't think we do.
> 
> I need them in order to generate COMDAT sections compatible with the
> HPUX linker.  gcc might emit e.g.
> 
>      .section .text 
>      # non-COMDAT code  ...
> 
>      .section .text,"G",symbol_name,comdat
>      # code for symbol_name ...
> 
>      .section .eh_frame
>      # non-COMDAT unwind info ...
> 
>      .section .eh_frame,"G",symbol_name,comdat
>      # unwind info for symbol_name ...
> 

I am testing this patch now.


H.J.

[-- Attachment #2: gas-elf-same-2.patch --]
[-- Type: text/plain, Size: 502 bytes --]

2004-04-30  H.J. Lu  <hongjiu.lu@intel.com>

	* symbols.c (symbol_set_bfdsym): Don't reset BFD section symbol.

--- gas/symbols.c.same	2003-12-04 10:43:25.000000000 -0800
+++ gas/symbols.c	2004-04-30 22:45:18.000000000 -0700
@@ -2260,7 +2260,8 @@ symbol_set_bfdsym (symbolS *s, asymbol *
 {
   if (LOCAL_SYMBOL_CHECK (s))
     s = local_symbol_convert ((struct local_symbol *) s);
-  s->bsym = bsym;
+  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
+    s->bsym = bsym;
 }
 
 #endif /* BFD_ASSEMBLER */

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  5:50               ` H. J. Lu
@ 2004-05-01  7:06                 ` H. J. Lu
  2004-05-01 14:44                   ` Alan Modra
  0 siblings, 1 reply; 15+ messages in thread
From: H. J. Lu @ 2004-05-01  7:06 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]

On Fri, Apr 30, 2004 at 10:50:08PM -0700, H. J. Lu wrote:
> On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> > Alan Modra <amodra@bigpond.net.au> writes:
> > 
> > > On Fri, Apr 30, 2004 at 08:43:00PM -0700, H. J. Lu wrote:
> > >> On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
> > >> > Actually, it is probably a mistake to try to support multiple sections
> > >> > of the same name in gas.  For instance, if you have two .text sections,
> > >> > how is gas supposed to evaluate ".long .text" ?
> > >> 
> > >> Will that be generated by compiler? If not, we can issue an error.
> > >
> > > The real question is: Do we need multiple sections of the same name
> > > in assembly files?  I don't think we do.
> > 
> > I need them in order to generate COMDAT sections compatible with the
> > HPUX linker.  gcc might emit e.g.
> > 
> >      .section .text 
> >      # non-COMDAT code  ...
> > 
> >      .section .text,"G",symbol_name,comdat
> >      # code for symbol_name ...
> > 
> >      .section .eh_frame
> >      # non-COMDAT unwind info ...
> > 
> >      .section .eh_frame,"G",symbol_name,comdat
> >      # unwind info for symbol_name ...
> > 
> 
> I am testing this patch now.
> 
> 
> H.J.

> 2004-04-30  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* symbols.c (symbol_set_bfdsym): Don't reset BFD section symbol.
> 

This patch is not enough. Here is an updated one.


H.J.

[-- Attachment #2: gas-elf-same-3.patch --]
[-- Type: text/plain, Size: 1162 bytes --]

2004-04-30  H.J. Lu  <hongjiu.lu@intel.com>

	* subsegs.c (section_symbol): Create a new section symbol if
	the existing one doesn't match.

	* symbols.c (symbol_set_bfdsym): Don't reset BFD section symbol.

--- gas/subsegs.c.same	2003-12-04 10:43:25.000000000 -0800
+++ gas/subsegs.c	2004-04-30 23:51:32.000000000 -0700
@@ -524,7 +524,9 @@ section_symbol (segT sec)
   else
     {
       s = symbol_find_base (sec->symbol->name, 0);
-      if (s == NULL)
+      /* We have to make sure it is the right symbol when we have
+	 multiple sections with the same section name.  */
+      if (s == NULL || S_GET_SEGMENT (s) != sec)
 	s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag);
       else
 	{
--- gas/symbols.c.same	2003-12-04 10:43:25.000000000 -0800
+++ gas/symbols.c	2004-04-30 23:52:45.000000000 -0700
@@ -2260,7 +2260,9 @@ symbol_set_bfdsym (symbolS *s, asymbol *
 {
   if (LOCAL_SYMBOL_CHECK (s))
     s = local_symbol_convert ((struct local_symbol *) s);
-  s->bsym = bsym;
+  /* Don't reset it if it is already a BFD section symbol.  */
+  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
+    s->bsym = bsym;
 }
 
 #endif /* BFD_ASSEMBLER */

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  5:12             ` Zack Weinberg
  2004-05-01  5:50               ` H. J. Lu
@ 2004-05-01  7:08               ` H. J. Lu
  1 sibling, 0 replies; 15+ messages in thread
From: H. J. Lu @ 2004-05-01  7:08 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: H. J. Lu, binutils

On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> Alan Modra <amodra@bigpond.net.au> writes:
> 
> > On Fri, Apr 30, 2004 at 08:43:00PM -0700, H. J. Lu wrote:
> >> On Sat, May 01, 2004 at 12:29:13PM +0930, Alan Modra wrote:
> >> > Actually, it is probably a mistake to try to support multiple sections
> >> > of the same name in gas.  For instance, if you have two .text sections,
> >> > how is gas supposed to evaluate ".long .text" ?
> >> 
> >> Will that be generated by compiler? If not, we can issue an error.
> >
> > The real question is: Do we need multiple sections of the same name
> > in assembly files?  I don't think we do.
> 
> I need them in order to generate COMDAT sections compatible with the
> HPUX linker.  gcc might emit e.g.
> 
>      .section .text 
>      # non-COMDAT code  ...
> 
>      .section .text,"G",symbol_name,comdat
>      # code for symbol_name ...
> 
>      .section .eh_frame
>      # non-COMDAT unwind info ...
> 
>      .section .eh_frame,"G",symbol_name,comdat
>      # unwind info for symbol_name ...

I am looking forward to that day :-). I will do my best to make sure
assembler and linker will handle them correctly.


H.J.

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01  7:06                 ` H. J. Lu
@ 2004-05-01 14:44                   ` Alan Modra
  2004-05-01 15:37                     ` H. J. Lu
  2004-05-01 18:42                     ` Zack Weinberg
  0 siblings, 2 replies; 15+ messages in thread
From: Alan Modra @ 2004-05-01 14:44 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Zack Weinberg, binutils

On Sat, May 01, 2004 at 12:06:18AM -0700, H. J. Lu wrote:
> On Fri, Apr 30, 2004 at 10:50:08PM -0700, H. J. Lu wrote:
> > On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> > > Alan Modra <amodra@bigpond.net.au> writes:
> > > > The real question is: Do we need multiple sections of the same name
> > > > in assembly files?  I don't think we do.
> > > 
> > > I need them in order to generate COMDAT sections compatible with the
> > > HPUX linker.  gcc might emit e.g.
> > > 
> > >      .section .text 
> > >      # non-COMDAT code  ...
> > > 
> > >      .section .text,"G",symbol_name,comdat
> > >      # code for symbol_name ...

Hmm, it wouldn't be much harder to use

     .section .text.symbol_name,"G",symbol_name,comdat
     # code for symbol_name ...

I fear HJ is going to be repeating the following a few more times.. 

> This patch is not enough. Here is an updated one.

[snip]
> +  /* Don't reset it if it is already a BFD section symbol.  */
> +  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
> +    s->bsym = bsym;

This is a useless comment.  It just says what anyone can see from the
next line of code.  It would be better to say _why_ it is necessary to
treat section symbols specially.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01 14:44                   ` Alan Modra
@ 2004-05-01 15:37                     ` H. J. Lu
  2004-05-01 17:31                       ` H. J. Lu
  2004-05-01 18:42                     ` Zack Weinberg
  1 sibling, 1 reply; 15+ messages in thread
From: H. J. Lu @ 2004-05-01 15:37 UTC (permalink / raw)
  To: Zack Weinberg, binutils

On Sun, May 02, 2004 at 12:14:39AM +0930, Alan Modra wrote:
> On Sat, May 01, 2004 at 12:06:18AM -0700, H. J. Lu wrote:
> > On Fri, Apr 30, 2004 at 10:50:08PM -0700, H. J. Lu wrote:
> > > On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> > > > Alan Modra <amodra@bigpond.net.au> writes:
> > > > > The real question is: Do we need multiple sections of the same name
> > > > > in assembly files?  I don't think we do.
> > > > 
> > > > I need them in order to generate COMDAT sections compatible with the
> > > > HPUX linker.  gcc might emit e.g.
> > > > 
> > > >      .section .text 
> > > >      # non-COMDAT code  ...
> > > > 
> > > >      .section .text,"G",symbol_name,comdat
> > > >      # code for symbol_name ...
> 
> Hmm, it wouldn't be much harder to use
> 
>      .section .text.symbol_name,"G",symbol_name,comdat
>      # code for symbol_name ...
> 
> I fear HJ is going to be repeating the following a few more times.. 
> 

I am ready for it.

> > This patch is not enough. Here is an updated one.
> 
> [snip]
> > +  /* Don't reset it if it is already a BFD section symbol.  */
> > +  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
> > +    s->bsym = bsym;

This patch is no longer needed for multiple section with the same
name. The section_symbol patch is enough.

> 
> This is a useless comment.  It just says what anyone can see from the
> next line of code.  It would be better to say _why_ it is necessary to
> treat section symbols specially.
> 

Since now we create multiple symbols with the same name, I think
we need a new interface to lookup symbols with matching section.


H.J.
-----
2004-04-30  H.J. Lu  <hongjiu.lu@intel.com>

	* subsegs.c (section_symbol): Create a new section symbol if
	the existing one doesn't match.

--- gas/subsegs.c.same	2003-12-04 10:43:25.000000000 -0800
+++ gas/subsegs.c	2004-04-30 23:51:32.000000000 -0700
@@ -524,7 +524,9 @@ section_symbol (segT sec)
   else
     {
       s = symbol_find_base (sec->symbol->name, 0);
-      if (s == NULL)
+      /* We have to make sure it is the right symbol when we have
+	 multiple sections with the same section name.  */
+      if (s == NULL || S_GET_SEGMENT (s) != sec)
 	s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag);
       else
 	{

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01 15:37                     ` H. J. Lu
@ 2004-05-01 17:31                       ` H. J. Lu
  0 siblings, 0 replies; 15+ messages in thread
From: H. J. Lu @ 2004-05-01 17:31 UTC (permalink / raw)
  To: Zack Weinberg, binutils

On Sat, May 01, 2004 at 08:37:20AM -0700, H. J. Lu wrote:
> On Sun, May 02, 2004 at 12:14:39AM +0930, Alan Modra wrote:
> > On Sat, May 01, 2004 at 12:06:18AM -0700, H. J. Lu wrote:
> > > On Fri, Apr 30, 2004 at 10:50:08PM -0700, H. J. Lu wrote:
> > > > On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> > > > > Alan Modra <amodra@bigpond.net.au> writes:
> > > > > > The real question is: Do we need multiple sections of the same name
> > > > > > in assembly files?  I don't think we do.
> > > > > 
> > > > > I need them in order to generate COMDAT sections compatible with the
> > > > > HPUX linker.  gcc might emit e.g.
> > > > > 
> > > > >      .section .text 
> > > > >      # non-COMDAT code  ...
> > > > > 
> > > > >      .section .text,"G",symbol_name,comdat
> > > > >      # code for symbol_name ...
> > 
> > Hmm, it wouldn't be much harder to use
> > 
> >      .section .text.symbol_name,"G",symbol_name,comdat
> >      # code for symbol_name ...
> > 
> > I fear HJ is going to be repeating the following a few more times.. 
> > 
> 
> I am ready for it.
> 
> > > This patch is not enough. Here is an updated one.
> > 
> > [snip]
> > > +  /* Don't reset it if it is already a BFD section symbol.  */
> > > +  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
> > > +    s->bsym = bsym;
> 
> This patch is no longer needed for multiple section with the same
> name. The section_symbol patch is enough.
> 
> > 
> > This is a useless comment.  It just says what anyone can see from the
> > next line of code.  It would be better to say _why_ it is necessary to
> > treat section symbols specially.
> > 
> 
> Since now we create multiple symbols with the same name, I think
> we need a new interface to lookup symbols with matching section.
> 
> 

I was wrong on both. We don't need a new interface for symbol lookup.
Also we do need the symbol_set_bfdsym change.


H.J.
----
2004-05-01  H.J. Lu  <hongjiu.lu@intel.com>

	* subsegs.c (section_symbol): Create a new section symbol if
	the existing one doesn't match.

	* symbols.c (symbol_set_bfdsym): Don't reset BFD section symbol.

--- gas/subsegs.c.same	2003-12-04 10:43:25.000000000 -0800
+++ gas/subsegs.c	2004-05-01 09:13:31.000000000 -0700
@@ -524,7 +524,9 @@ section_symbol (segT sec)
   else
     {
       s = symbol_find_base (sec->symbol->name, 0);
-      if (s == NULL)
+      /* We have to make sure it is the right symbol when we have
+	 multiple sections with the same section name.  */
+      if (s == NULL || S_GET_SEGMENT (s) != sec)
 	s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag);
       else
 	{
--- gas/symbols.c.same	2004-05-01 07:55:53.000000000 -0700
+++ gas/symbols.c	2004-05-01 10:11:31.000000000 -0700
@@ -2260,7 +2260,15 @@ symbol_set_bfdsym (symbolS *s, asymbol *
 {
   if (LOCAL_SYMBOL_CHECK (s))
     s = local_symbol_convert ((struct local_symbol *) s);
-  s->bsym = bsym;
+  /* Usually, it is harmless to reset a symbol to a BFD section
+     symbol. For example, obj_elf_change_section sets the BFD symbol
+     of an old symbol with the newly created section symbol. But when
+     we have multiple sections with the same name, the newly created
+     section may have the same name as an old section. We check if the
+     old symbol has been already marked as a section symbol before
+     resetting it.  */
+  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
+    s->bsym = bsym;
 }
 
 #endif /* BFD_ASSEMBLER */

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

* Re: PATCH: Multiple sections with same name don't work
  2004-05-01 14:44                   ` Alan Modra
  2004-05-01 15:37                     ` H. J. Lu
@ 2004-05-01 18:42                     ` Zack Weinberg
  1 sibling, 0 replies; 15+ messages in thread
From: Zack Weinberg @ 2004-05-01 18:42 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

Alan Modra <amodra@bigpond.net.au> writes:

> On Sat, May 01, 2004 at 12:06:18AM -0700, H. J. Lu wrote:
>> On Fri, Apr 30, 2004 at 10:50:08PM -0700, H. J. Lu wrote:
>> > On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
>> > > Alan Modra <amodra@bigpond.net.au> writes:
>> > > > The real question is: Do we need multiple sections of the same name
>> > > > in assembly files?  I don't think we do.
>> > > 
>> > > I need them in order to generate COMDAT sections compatible with the
>> > > HPUX linker.  gcc might emit e.g.
>> > > 
>> > >      .section .text 
>> > >      # non-COMDAT code  ...
>> > > 
>> > >      .section .text,"G",symbol_name,comdat
>> > >      # code for symbol_name ...
>
> Hmm, it wouldn't be much harder to use
>
>      .section .text.symbol_name,"G",symbol_name,comdat
>      # code for symbol_name ...

That may not work.  Unfortunately, the HPUX linker's COMDAT-group
support is only partially documented, and subtly incompatible with the
standard ELF SHT_GROUP notion.  I am having to work things out by
reverse engineering what aCC does -- and it uses multiple sections
with the same name.

zw

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

end of thread, other threads:[~2004-05-01 18:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-30 22:31 Multiple sections with same name don't work H. J. Lu
     [not found] ` <20040430230129.GA17907@lucon.org>
2004-05-01  0:36   ` PATCH: " H. J. Lu
2004-05-01  2:31     ` Alan Modra
2004-05-01  2:59       ` Alan Modra
2004-05-01  3:43         ` H. J. Lu
2004-05-01  4:25           ` Alan Modra
2004-05-01  4:34             ` H. J. Lu
2004-05-01  5:12             ` Zack Weinberg
2004-05-01  5:50               ` H. J. Lu
2004-05-01  7:06                 ` H. J. Lu
2004-05-01 14:44                   ` Alan Modra
2004-05-01 15:37                     ` H. J. Lu
2004-05-01 17:31                       ` H. J. Lu
2004-05-01 18:42                     ` Zack Weinberg
2004-05-01  7:08               ` H. J. Lu

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).