public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
* Arch maintainers: new approach for crti.o and crtn.o
@ 2012-02-08  1:56 Joseph S. Myers
  2012-02-10 20:23 ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Joseph S. Myers @ 2012-02-08  1:56 UTC (permalink / raw)
  To: libc-alpha, libc-ports

glibc now supports building crti.o and crtn.o (both the csu/ versions and 
the nptl/ versions) from .S files, instead of the very fragile approach 
(which kept breaking with GCC changes) of postprocessing .s output from 
initfini.c and pt-initfini.c to separate function prologues and epilogues 
into separate files.

I have converted i386 to the new scheme so it serves as an example.  The 
maintainers of each other architecture should convert it; the crt[in].S 
files generated in csu/ and nptl/ in the object directory from a glibc 
build may serve as a starting point to clean up and check in.

(You will of course want the checked-in files to work on all supported 
variants of your architecture, not just the one for which your compiler 
was configured when building initfini.c and pt-initfini.c.  Some 
architectures have CFLAGS settings forcing particular CPU options when 
building those C files, others do not.  In any case, after the conversion 
for a particular architecture, any special makefile settings for the old 
approach with that architecture can be removed, as can any 
architecture-specific versions of initfini.c and pt-initfini.c.)

The deadline for the conversion, after which the transitional support for 
the old mechanism is expected to be removed, is 1 April (it may be removed 
before then if all libc architectures are converted sooner).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-08  1:56 Arch maintainers: new approach for crti.o and crtn.o Joseph S. Myers
@ 2012-02-10 20:23 ` David Miller
  2012-02-10 21:02   ` Roland McGrath
  2012-02-10 21:42   ` Joseph S. Myers
  0 siblings, 2 replies; 9+ messages in thread
From: David Miller @ 2012-02-10 20:23 UTC (permalink / raw)
  To: joseph; +Cc: libc-alpha, libc-ports

From: "Joseph S. Myers" <joseph@codesourcery.com>
Date: Wed, 8 Feb 2012 01:56:03 +0000 (UTC)

> glibc now supports building crti.o and crtn.o (both the csu/ versions and 
> the nptl/ versions) from .S files, instead of the very fragile approach 
> (which kept breaking with GCC changes) of postprocessing .s output from 
> initfini.c and pt-initfini.c to separate function prologues and epilogues 
> into separate files.

Joseph, I have this almost done for sparc but I've run into one snag.

Sparc needs "-fPIC" specified when turning assembler files into objects,
because this changes what relocations are generated.  For example, for
a call instruction R_SPARC_WDISP30 is generated for non-PIC vs.
R_SPARC_WPLT30 for PIC.

This worked beforehand because we go "ASFLAGS-.os = -fPIC" in the
Sparc Makefile fragments.

However, the csu/ and nptl/ Makefile fragments now do the
"$(ASFLAGS-.os)" thing only in the backwards compatability case.  I
need it to happen unconditionally whenever we build crt{i,n}.o and
related objects (such as pt-crti.o).

Is there any particular reason you hid the ASFLAGS stuff exclusively
into the backwards compat case?  I guess it's to deal with the "defs.h"
dependency which doesn't exist when crt{i,n}.S are provided by the
architecture.

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-10 20:23 ` David Miller
@ 2012-02-10 21:02   ` Roland McGrath
  2012-02-10 21:42   ` Joseph S. Myers
  1 sibling, 0 replies; 9+ messages in thread
From: Roland McGrath @ 2012-02-10 21:02 UTC (permalink / raw)
  To: David Miller; +Cc: joseph, libc-alpha, libc-ports

We could add a use of $(ASFLAGS-$(<F)) to be consistent with CFLAGS.  

What Joseph did for one of the other machines was just set CPPFLAGS-crti.S
since compile.S refers to CPPFLAGS.


Thanks,
Roland

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-10 20:23 ` David Miller
  2012-02-10 21:02   ` Roland McGrath
@ 2012-02-10 21:42   ` Joseph S. Myers
  2012-02-14 19:57     ` David Miller
  1 sibling, 1 reply; 9+ messages in thread
From: Joseph S. Myers @ 2012-02-10 21:42 UTC (permalink / raw)
  To: David Miller; +Cc: libc-alpha, libc-ports

On Fri, 10 Feb 2012, David Miller wrote:

> Is there any particular reason you hid the ASFLAGS stuff exclusively
> into the backwards compat case?  I guess it's to deal with the "defs.h"
> dependency which doesn't exist when crt{i,n}.S are provided by the
> architecture.

In general I think an improvement with the new scheme is that you avoid 
special makefile rules for these targets (instead they can be built the 
same way as other objects) and such a special rule is where the 
$(ASFLAGS-.os) was.  As noted, CPPFLAGS can be used to get these options 
in - although adding support for $(ASFLAGS-$(<F)) would be cleaner - but I 
think it's better for architectures to end up setting such a variable if 
needed for these targets (just as various architectures previously set 
special options when building initfini.c) than to have a special makefile 
rule with custom commands.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-10 21:42   ` Joseph S. Myers
@ 2012-02-14 19:57     ` David Miller
  2012-02-14 20:10       ` Roland McGrath
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2012-02-14 19:57 UTC (permalink / raw)
  To: joseph; +Cc: libc-alpha, libc-ports

From: "Joseph S. Myers" <joseph@codesourcery.com>
Date: Fri, 10 Feb 2012 21:41:53 +0000 (UTC)

> On Fri, 10 Feb 2012, David Miller wrote:
> 
>> Is there any particular reason you hid the ASFLAGS stuff exclusively
>> into the backwards compat case?  I guess it's to deal with the "defs.h"
>> dependency which doesn't exist when crt{i,n}.S are provided by the
>> architecture.
> 
> In general I think an improvement with the new scheme is that you avoid 
> special makefile rules for these targets (instead they can be built the 
> same way as other objects) and such a special rule is where the 
> $(ASFLAGS-.os) was.  As noted, CPPFLAGS can be used to get these options 
> in - although adding support for $(ASFLAGS-$(<F)) would be cleaner - but I 
> think it's better for architectures to end up setting such a variable if 
> needed for these targets (just as various architectures previously set 
> special options when building initfini.c) than to have a special makefile 
> rule with custom commands.

I'm not so sure I buy this, this puts the burdon on the wrong side
of the equation.

Using the $(ASFLAGS-.os) variable is perfect for this kind of
situation, where you have foo.o files built from assembler files that
need to be PIC.

All these other schemes being described put the burdon on the target
maintainer to keep track of exactly which object files fall into this
category.  And that is very error prone.  It took me hours to figure
out where I'd need to hook in all the various cases in the Sparc
Makefile fragments, including NPTL.

And then tomorrow if, for example, someone changes nptl/pt-crtn.o to
be named just plain nptl/crtn.o, all the targets have to adjust their
Makefile chunks again.

That doesn't make any sense to me, and again it seems extremely error
prone.

Whereas the $(ASFLAGS-.os) solution requires only the person making
generic glibc changes to get this specification right.

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-14 19:57     ` David Miller
@ 2012-02-14 20:10       ` Roland McGrath
  2012-02-14 20:24         ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Roland McGrath @ 2012-02-14 20:10 UTC (permalink / raw)
  To: David Miller; +Cc: joseph, libc-alpha, libc-ports

It sounds to me like we should just be building crt[in].os instead,
so they get all the normal machinery for PIC-compatible objects.
Would that work?


Thanks,
Roland

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-14 20:10       ` Roland McGrath
@ 2012-02-14 20:24         ` David Miller
  2012-02-14 20:37           ` Roland McGrath
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2012-02-14 20:24 UTC (permalink / raw)
  To: roland; +Cc: joseph, libc-alpha, libc-ports

From: Roland McGrath <roland@hack.frob.com>
Date: Tue, 14 Feb 2012 12:09:53 -0800 (PST)

> It sounds to me like we should just be building crt[in].os instead,
> so they get all the normal machinery for PIC-compatible objects.
> Would that work?

Absolutely it shoudl work

Are you then going to do something with symlinks or similar to end up
with the crt{n,i}.o names in the end?

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-14 20:24         ` David Miller
@ 2012-02-14 20:37           ` Roland McGrath
  2012-02-15 21:12             ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Roland McGrath @ 2012-02-14 20:37 UTC (permalink / raw)
  To: David Miller; +Cc: joseph, libc-alpha, libc-ports

> Are you then going to do something with symlinks or similar to end up
> with the crt{n,i}.o names in the end?

It seems likely that having those names will make things easiest all around.
So yes, I'd figured we'd probably have:

$(objpfx)crti.o $(objpfx)crtn.o: $(objpfx)%.o: $(objpfx)%.os
	ln -f $< $@

or something like that.


Thanks,
Roland

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

* Re: Arch maintainers: new approach for crti.o and crtn.o
  2012-02-14 20:37           ` Roland McGrath
@ 2012-02-15 21:12             ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2012-02-15 21:12 UTC (permalink / raw)
  To: roland; +Cc: joseph, libc-alpha, libc-ports

From: Roland McGrath <roland@hack.frob.com>
Date: Tue, 14 Feb 2012 12:37:36 -0800 (PST)

>> Are you then going to do something with symlinks or similar to end up
>> with the crt{n,i}.o names in the end?
> 
> It seems likely that having those names will make things easiest all around.
> So yes, I'd figured we'd probably have:
> 
> $(objpfx)crti.o $(objpfx)crtn.o: $(objpfx)%.o: $(objpfx)%.os
> 	ln -f $< $@
> 
> or something like that.

Ok, for now I've checked in the following using the CPPFLAGS approach
so we can make forward progress.  I guess only s390 is left using
the initfini.c crud now?

--------------------
Move sparc away from the deprecated inifini.c scheme.

/

	* sysdeps/sparc/Makefile: Add -fPIC when building crt{i,n}.S
	* sysdeps/sparc/crti.S: New file.
	* sysdeps/sparc/crtn.S: New file.
	* sysdeps/sparc/sparc32/Makefile: Remove initfini handling.
	* sysdeps/sparc/sparc64/Makefile: Likewise.

nptl/

	* sysdeps/sparc/Makefile: Add -fPIC when building pt-crti.S and crtn.S
---
 ChangeLog                      |    8 +++
 nptl/ChangeLog                 |    4 ++
 nptl/sysdeps/sparc/Makefile    |    5 ++
 sysdeps/sparc/Makefile         |    2 +
 sysdeps/sparc/crti.S           |  104 ++++++++++++++++++++++++++++++++++++++++
 sysdeps/sparc/crtn.S           |   45 +++++++++++++++++
 sysdeps/sparc/sparc32/Makefile |    4 --
 sysdeps/sparc/sparc64/Makefile |    4 --
 8 files changed, 168 insertions(+), 8 deletions(-)
 create mode 100644 sysdeps/sparc/crti.S
 create mode 100644 sysdeps/sparc/crtn.S

diff --git a/ChangeLog b/ChangeLog
index cb00422..131caa6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-02-16  David S. Miller  <davem@davemloft.net>
+
+	* sysdeps/sparc/Makefile: Add -fPIC when building crt{i,n}.S
+	* sysdeps/sparc/crti.S: New file.
+	* sysdeps/sparc/crtn.S: New file.
+	* sysdeps/sparc/sparc32/Makefile: Remove initfini handling.
+	* sysdeps/sparc/sparc64/Makefile: Likewise.
+
 2012-02-15  Mike Frysinger  <vapier@gentoo.org>
 
 	* sysdeps/unix/sysv/linux/getcwd.c: Include sys/param.h.
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 657c2b0..bda2334 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,7 @@
+2012-02-16  David S. Miller  <davem@davemloft.net>
+
+	* sysdeps/sparc/Makefile: Add -fPIC when building pt-crti.S and crtn.S
+
 2012-02-15  Marek Polacek  <polacek@redhat.com>
 
 	* sysdeps/unix/sysv/linux/x86_64/Makefile: Remove file.
diff --git a/nptl/sysdeps/sparc/Makefile b/nptl/sysdeps/sparc/Makefile
index 81bddf6..5372867 100644
--- a/nptl/sysdeps/sparc/Makefile
+++ b/nptl/sysdeps/sparc/Makefile
@@ -1,3 +1,8 @@
 ifeq ($(subdir),csu)
 gen-as-const-headers += tcb-offsets.sym
 endif
+
+ifeq ($(subdir),nptl)
+CPPFLAGS-pt-crti.S += -fPIC
+CPPFLAGS-crtn.S += -fPIC
+endif
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
index 735e4a4..45609d5 100644
--- a/sysdeps/sparc/Makefile
+++ b/sysdeps/sparc/Makefile
@@ -14,4 +14,6 @@ endif
 ifeq ($(subdir),csu)
 # get offset to rtld_global._dl_hwcap
 gen-as-const-headers += rtld-global-offsets.sym
+CPPFLAGS-crti.S += -fPIC
+CPPFLAGS-crtn.S += -fPIC
 endif
diff --git a/sysdeps/sparc/crti.S b/sysdeps/sparc/crti.S
new file mode 100644
index 0000000..adb1b29
--- /dev/null
+++ b/sysdeps/sparc/crti.S
@@ -0,0 +1,104 @@
+/* Special .init and .fini section support for sparc.
+   Copyright (C) 1995-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* crti.S puts a function prologue at the beginning of the .init and
+   .fini sections and defines global symbols for those addresses, so
+   they can be called as functions.  The symbols _init and _fini are
+   magic and cause the linker to emit DT_INIT and DT_FINI.  */
+
+#include <libc-symbols.h>
+#include <sysdep.h>
+
+#ifndef PREINIT_FUNCTION
+# define PREINIT_FUNCTION __gmon_start__
+#endif
+
+#ifndef PREINIT_FUNCTION_WEAK
+# define PREINIT_FUNCTION_WEAK 1
+#endif
+
+#if PREINIT_FUNCTION_WEAK
+	weak_extern (PREINIT_FUNCTION)
+#else
+	.hidden PREINIT_FUNCTION
+#endif
+
+#ifdef __arch64__
+#define	STACKFRAME_SIZE	176
+#define GOT_LOAD	ldx
+#else
+#define	STACKFRAME_SIZE	96
+#define GOT_LOAD	ld
+#endif
+
+	.section	.init,"ax",@progbits
+	.p2align	2
+	.globl		_init
+	.type		_init, @function
+_init:
+	save		%sp, -STACKFRAME_SIZE, %sp
+#if PREINIT_FUNCTION_WEAK
+	sethi		%hi(_GLOBAL_OFFSET_TABLE_-4), %l7
+	call		__sparc_get_pc_thunk.l7
+	 add		%l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
+	sethi		%hi(PREINIT_FUNCTION), %g1
+	or		%g1, %lo(PREINIT_FUNCTION), %g1
+	GOT_LOAD	[%l7 + %g1], %g1
+	cmp		%g1, 0
+	be		1f
+	 nop
+	call		PREINIT_FUNCTION
+	 nop
+1:
+#else
+	call		PREINIT_FUNCTION
+	 nop
+#endif
+
+	.section	.fini,"ax",@progbits
+	.p2align	2
+	.globl		_fini
+	.type		_fini, @function
+_fini:
+	save		%sp, -STACKFRAME_SIZE, %sp
+
+	.section	.text.__sparc_get_pc_thunk.l7,"axG",@progbits,__sparc_get_pc_thunk.l7,comdat
+	.p2align	2
+	.weak		__sparc_get_pc_thunk.l7
+	.hidden		__sparc_get_pc_thunk.l7
+	.type		__sparc_get_pc_thunk.l7, #function
+__sparc_get_pc_thunk.l7:
+	jmp		%o7 + 8
+	 add		%o7, %l7, %l7
diff --git a/sysdeps/sparc/crtn.S b/sysdeps/sparc/crtn.S
new file mode 100644
index 0000000..8f3e89a
--- /dev/null
+++ b/sysdeps/sparc/crtn.S
@@ -0,0 +1,45 @@
+/* Special .init and .fini section support for sparc.
+   Copyright (C) 1995-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* crtn.S puts function epilogues in the .init and .fini sections
+   corresponding to the prologues in crti.S. */
+
+	.section	.init,"ax",@progbits
+	jmp		%i7 + 8
+	restore
+
+	.section	.fini,"ax",@progbits
+	jmp		%i7 + 8
+	restore
diff --git a/sysdeps/sparc/sparc32/Makefile b/sysdeps/sparc/sparc32/Makefile
index cc2bb08..fb1adaf 100644
--- a/sysdeps/sparc/sparc32/Makefile
+++ b/sysdeps/sparc/sparc32/Makefile
@@ -19,10 +19,6 @@ ifeq ($(subdir),gnulib)
 sysdep_routines = dotmul umul $(divrem) alloca
 endif	# gnulib
 
-ifeq ($(subdir),csu)
-CFLAGS-initfini.s += -mcpu=v7
-endif
-
 # We distribute these files, even though they are generated,
 # so as to avoid the need for a functioning m4 to build the library.
 divrem := sdiv udiv rem urem
diff --git a/sysdeps/sparc/sparc64/Makefile b/sysdeps/sparc/sparc64/Makefile
index 1a859df..fb8b011 100644
--- a/sysdeps/sparc/sparc64/Makefile
+++ b/sysdeps/sparc/sparc64/Makefile
@@ -3,10 +3,6 @@ sysdep_routines += hp-timing
 elide-routines.os += hp-timing
 endif
 
-ifeq ($(subdir),csu)
-CFLAGS-initfini.s += -mcpu=v9
-endif
-
 ifeq ($(subdir),string)
 sysdep_routines += align-cpy
 endif
-- 
1.7.6.401.g6a319

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

end of thread, other threads:[~2012-02-15 21:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-08  1:56 Arch maintainers: new approach for crti.o and crtn.o Joseph S. Myers
2012-02-10 20:23 ` David Miller
2012-02-10 21:02   ` Roland McGrath
2012-02-10 21:42   ` Joseph S. Myers
2012-02-14 19:57     ` David Miller
2012-02-14 20:10       ` Roland McGrath
2012-02-14 20:24         ` David Miller
2012-02-14 20:37           ` Roland McGrath
2012-02-15 21:12             ` David Miller

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