public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix tst-array* on x86_64
@ 2002-12-10  5:52 Jakub Jelinek
  2002-12-10  9:43 ` H. J. Lu
  2002-12-10 10:47 ` Ulrich Drepper
  0 siblings, 2 replies; 8+ messages in thread
From: Jakub Jelinek @ 2002-12-10  5:52 UTC (permalink / raw)
  To: Roland McGrath, Ulrich Drepper; +Cc: Glibc hackers

Hi!

This is actually the same crap as I had to work around in test-string.h,
ie. x86_64 aligns preinit_array etc. to 16 bytes because they are >=
16 bytes, yet its actual size is 24 bytes.
  /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
     to 16byte boundary.  */
Linker script of course doesn't expect .init_array/.fini_array/.preinit_array
sections to be more than word aligned and thus the labels around them
are on wrong positions.

2002-12-10  Jakub Jelinek  <jakub@redhat.com>

	* elf/tst-array1.c (preinit_array, init_array, fini_array):
	Explicitely align the array to sizeof (void *).
	* elf/tst-array2dep.c (init_array, fini_array): Likewise.

--- libc/elf/tst-array1.c.jj	2002-11-07 23:28:04.000000000 +0100
+++ libc/elf/tst-array1.c	2002-12-10 16:01:54.000000000 +0100
@@ -35,7 +35,7 @@ preinit_2 (void)
 }
 
 void (*const preinit_array []) (void)
-     __attribute__ ((section (".preinit_array"))) =
+     __attribute__ ((section (".preinit_array"), aligned (sizeof (void *)))) =
 {
   &preinit_0,
   &preinit_1,
@@ -60,7 +60,8 @@ init_2 (void)
   write (STDOUT_FILENO, "init array 2\n", 13);
 }
 
-void (*const init_array []) (void) __attribute__ ((section (".init_array"))) =
+void (*const init_array []) (void)
+     __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) =
 {
   &init_0,
   &init_1,
@@ -85,7 +86,8 @@ fini_2 (void)
   write (STDOUT_FILENO, "fini array 2\n", 13);
 }
 
-void (*const fini_array []) (void) __attribute__ ((section (".fini_array"))) =
+void (*const fini_array []) (void)
+     __attribute__ ((section (".fini_array"), aligned (sizeof (void *)))) =
 {
   &fini_0,
   &fini_1,
--- libc/elf/tst-array2dep.c.jj	2002-11-07 23:28:04.000000000 +0100
+++ libc/elf/tst-array2dep.c	2002-12-10 16:02:34.000000000 +0100
@@ -34,7 +34,8 @@ init_2 (void)
   write (STDOUT_FILENO, "DSO init array 2\n", 17);
 }
 
-void (*const init_array []) (void) __attribute__ ((section (".init_array"))) =
+void (*const init_array []) (void)
+     __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) =
 {
   &init_0,
   &init_1,
@@ -59,7 +60,8 @@ fini_2 (void)
   write (STDOUT_FILENO, "DSO fini array 2\n", 17);
 }
 
-void (*const fini_array []) (void) __attribute__ ((section (".fini_array"))) =
+void (*const fini_array []) (void)
+     __attribute__ ((section (".fini_array"), aligned (sizeof (void *)))) =
 {
   &fini_0,
   &fini_1,

	Jakub

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10  5:52 [PATCH] Fix tst-array* on x86_64 Jakub Jelinek
@ 2002-12-10  9:43 ` H. J. Lu
  2002-12-10 10:06   ` Jakub Jelinek
  2002-12-10 10:47 ` Ulrich Drepper
  1 sibling, 1 reply; 8+ messages in thread
From: H. J. Lu @ 2002-12-10  9:43 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, Ulrich Drepper, Glibc hackers, binutils

On Tue, Dec 10, 2002 at 02:52:50PM +0100, Jakub Jelinek wrote:
> Hi!
> 
> This is actually the same crap as I had to work around in test-string.h,
> ie. x86_64 aligns preinit_array etc. to 16 bytes because they are >=
> 16 bytes, yet its actual size is 24 bytes.
>   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
>      to 16byte boundary.  */
> Linker script of course doesn't expect .init_array/.fini_array/.preinit_array
> sections to be more than word aligned and thus the labels around them
> are on wrong positions.
> 
> 2002-12-10  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* elf/tst-array1.c (preinit_array, init_array, fini_array):
> 	Explicitely align the array to sizeof (void *).
> 	* elf/tst-array2dep.c (init_array, fini_array): Likewise.
> 
> --- libc/elf/tst-array1.c.jj	2002-11-07 23:28:04.000000000 +0100
> +++ libc/elf/tst-array1.c	2002-12-10 16:01:54.000000000 +0100
> @@ -35,7 +35,7 @@ preinit_2 (void)
>  }
>  
>  void (*const preinit_array []) (void)
> -     __attribute__ ((section (".preinit_array"))) =
> +     __attribute__ ((section (".preinit_array"), aligned (sizeof (void *)))) =
>  {
>    &preinit_0,
>    &preinit_1,

I assume size of void * is 8 byte for x86_64. Will it align at 16 byte?
Those *_array sections are special sections. Should they be handled by
gas/ld automatically?


H.J.

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10  9:43 ` H. J. Lu
@ 2002-12-10 10:06   ` Jakub Jelinek
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Jelinek @ 2002-12-10 10:06 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Roland McGrath, Ulrich Drepper, Glibc hackers, binutils

On Tue, Dec 10, 2002 at 09:43:08AM -0800, H. J. Lu wrote:
> On Tue, Dec 10, 2002 at 02:52:50PM +0100, Jakub Jelinek wrote:
> > Hi!
> > 
> > This is actually the same crap as I had to work around in test-string.h,
> > ie. x86_64 aligns preinit_array etc. to 16 bytes because they are >=
> > 16 bytes, yet its actual size is 24 bytes.
> >   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
> >      to 16byte boundary.  */
> > Linker script of course doesn't expect .init_array/.fini_array/.preinit_array
> > sections to be more than word aligned and thus the labels around them
> > are on wrong positions.
> > 
> > 2002-12-10  Jakub Jelinek  <jakub@redhat.com>
> > 
> > 	* elf/tst-array1.c (preinit_array, init_array, fini_array):
> > 	Explicitely align the array to sizeof (void *).
> > 	* elf/tst-array2dep.c (init_array, fini_array): Likewise.
> > 
> > --- libc/elf/tst-array1.c.jj	2002-11-07 23:28:04.000000000 +0100
> > +++ libc/elf/tst-array1.c	2002-12-10 16:01:54.000000000 +0100
> > @@ -35,7 +35,7 @@ preinit_2 (void)
> >  }
> >  
> >  void (*const preinit_array []) (void)
> > -     __attribute__ ((section (".preinit_array"))) =
> > +     __attribute__ ((section (".preinit_array"), aligned (sizeof (void *)))) =
> >  {
> >    &preinit_0,
> >    &preinit_1,
> 
> I assume size of void * is 8 byte for x86_64. Will it align at 16 byte?

Yes. It will align that way any array whose entries are aligned to <= 16 bytes
and whose size is >= 16 bytes.
E.g. if:
void (*const preinit_array_0) (void) __attribute__ ((section (".preinit_array"))) = &preinit_0;
void (*const preinit_array_1) (void) __attribute__ ((section (".preinit_array"))) = &preinit_1;
void (*const preinit_array_2) (void) __attribute__ ((section (".preinit_array"))) = &preinit_2;
was used instead, it would be just 8 aligned.

> Those *_array sections are special sections. Should they be handled by
> gas/ld automatically?

It is gcc's problem (and in this case testcase writer's problem) to follow
the rules.

	Jakub

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10  5:52 [PATCH] Fix tst-array* on x86_64 Jakub Jelinek
  2002-12-10  9:43 ` H. J. Lu
@ 2002-12-10 10:47 ` Ulrich Drepper
  2002-12-10 15:25   ` Roland McGrath
  1 sibling, 1 reply; 8+ messages in thread
From: Ulrich Drepper @ 2002-12-10 10:47 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, Glibc hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jakub Jelinek wrote:

> 2002-12-10  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* elf/tst-array1.c (preinit_array, init_array, fini_array):
> 	Explicitely align the array to sizeof (void *).
> 	* elf/tst-array2dep.c (init_array, fini_array): Likewise.

Why are the labels around wrong?  I would imagine that padding is added
and that if two .preinit_array sections have to be concatenated there is
garbage between them.  But still, the lables should be rights.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE99ja52ijCOnn/RHQRAvwSAJ9aA+a1iggio1V19h+wF5WkzhkYnwCgnHw/
eSRx2RYepz63ULEBS3sfz+U=
=vA3h
-----END PGP SIGNATURE-----

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10 10:47 ` Ulrich Drepper
@ 2002-12-10 15:25   ` Roland McGrath
  2002-12-10 15:44     ` H. J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2002-12-10 15:25 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Jakub Jelinek, Glibc hackers

> Why are the labels around wrong?  I would imagine that padding is added
> and that if two .preinit_array sections have to be concatenated there is
> garbage between them.  But still, the lables should be rights.

This padding is added by the compiler, inside the section.  
The labels are created by the linker.  i.e.: 

.globl preinit_array
	.section	.preinit_array,"a",@progbits
	.align 16
	.type	preinit_array, @object
	.size	preinit_array, 24
preinit_array:
	.quad ...

This doesn't explain exactly what I saw, which was the linker symbols and
the sections not starting at the same address.  But even if they matched,
the leading or trailing zeros bite.

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10 15:25   ` Roland McGrath
@ 2002-12-10 15:44     ` H. J. Lu
  2002-12-10 16:35       ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: H. J. Lu @ 2002-12-10 15:44 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Ulrich Drepper, Jakub Jelinek, Glibc hackers

On Tue, Dec 10, 2002 at 03:25:38PM -0800, Roland McGrath wrote:
> > Why are the labels around wrong?  I would imagine that padding is added
> > and that if two .preinit_array sections have to be concatenated there is
> > garbage between them.  But still, the lables should be rights.
> 
> This padding is added by the compiler, inside the section.  
> The labels are created by the linker.  i.e.: 
> 
> .globl preinit_array
> 	.section	.preinit_array,"a",@progbits
> 	.align 16
> 	.type	preinit_array, @object
> 	.size	preinit_array, 24
> preinit_array:
> 	.quad ...
> 
> This doesn't explain exactly what I saw, which was the linker symbols and
> the sections not starting at the same address.  But even if they matched,
> the leading or trailing zeros bite.

Does

  /* Ensure the __preinit_array_start label is properly aligned.  We
     could instead move the label definition inside the section, but
     the linker would then create the section even if it turns out to
     be empty, which isn't pretty.  */
  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}

explain what you saw?


H.J.

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10 15:44     ` H. J. Lu
@ 2002-12-10 16:35       ` Roland McGrath
  2002-12-10 16:56         ` H. J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2002-12-10 16:35 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Ulrich Drepper, Jakub Jelinek, Glibc hackers

I already read the linker script of course.  I don't see how that explains
it.  The ALIGN is done before the symbol or the section.  Ah, but you are
saying that the section will have sh_addralign of 16 and that will skip the
word after the symbol and before the section.  Of course, you didn't say
that so I can only assume that having me just get lucky and guess what you
meant was your way of being helpful.

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

* Re: [PATCH] Fix tst-array* on x86_64
  2002-12-10 16:35       ` Roland McGrath
@ 2002-12-10 16:56         ` H. J. Lu
  0 siblings, 0 replies; 8+ messages in thread
From: H. J. Lu @ 2002-12-10 16:56 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Ulrich Drepper, Jakub Jelinek, Glibc hackers

On Tue, Dec 10, 2002 at 04:35:54PM -0800, Roland McGrath wrote:
> I already read the linker script of course.  I don't see how that explains
> it.  The ALIGN is done before the symbol or the section.  Ah, but you are
> saying that the section will have sh_addralign of 16 and that will skip the
> word after the symbol and before the section.  Of course, you didn't say
> that so I can only assume that having me just get lucky and guess what you
> meant was your way of being helpful.

The linker script shows that __preinit_array_start is aligned by
ALIGN(${ALIGNMENT}). It doesn't matter what alignment .preinit_array
uses. A target has to make sure all __*_array_start are aligned
properly. The current elf.sc assumes ALIGN(${ALIGNMENT}) will align
all __*_array_start correctly. It seems to work for ia32 and ia64.


H.J.

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

end of thread, other threads:[~2002-12-11  0:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-10  5:52 [PATCH] Fix tst-array* on x86_64 Jakub Jelinek
2002-12-10  9:43 ` H. J. Lu
2002-12-10 10:06   ` Jakub Jelinek
2002-12-10 10:47 ` Ulrich Drepper
2002-12-10 15:25   ` Roland McGrath
2002-12-10 15:44     ` H. J. Lu
2002-12-10 16:35       ` Roland McGrath
2002-12-10 16:56         ` 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).