public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Allow main to come from a shared library for PIE [BZ #262]
@ 2004-07-15 12:48 Jakub Jelinek
  2004-07-15 22:02 ` Roland McGrath
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2004-07-15 12:48 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

2004-07-15  Jakub Jelinek  <jakub@redhat.com>

	[BZ #262]
	* sysdeps/i386/elf/start.S (_start): Use @GOT instead of @GOTOFF
	for main.  Patch by Solar Designer <solar@openwall.com>.
	* elf/Makefile: Add rules to build and run tst-pie1.
	* elf/tst-pie1.c: New test.
	* elf/tst-piemod1.c: New file.

--- libc/sysdeps/i386/elf/start.S.jj	2004-07-15 14:41:46.000000000 +0200
+++ libc/sysdeps/i386/elf/start.S	2004-07-15 14:42:37.000000000 +0200
@@ -1,5 +1,6 @@
 /* Startup code compliant to the ELF i386 ABI.
-   Copyright (C) 1995-1998,2000,2001,2002,2003 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
+   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
@@ -81,8 +82,7 @@ _start:
 	pushl %ecx		/* Push second argument: argv.  */
 	pushl %esi		/* Push first argument: argc.  */
 
-	leal BP_SYM (main)@GOTOFF(%ebx), %eax
-	pushl %eax
+	pushl BP_SYM (main)@GOT(%ebx)
 
 	/* Call the user's main function, and exit with its value.
 	   But let the libc call main.    */
--- libc/elf/tst-pie1.c.jj	2004-07-15 14:37:41.000000000 +0200
+++ libc/elf/tst-pie1.c	2004-07-15 14:37:41.000000000 +0200
@@ -0,0 +1,5 @@
+int
+foo (void)
+{
+  return 34;
+}
--- libc/elf/Makefile.jj	2004-06-17 17:08:46.000000000 +0200
+++ libc/elf/Makefile	2004-07-15 14:47:43.000000000 +0200
@@ -80,7 +80,7 @@ distribute	:= rtld-Rules \
 		   nodel2mod1.c nodel2mod2.c nodel2mod3.c \
 		   reldep9.c reldep9mod1.c reldep9mod2.c reldep9mod3.c \
 		   tst-array1.exp tst-array2.exp tst-array4.exp \
-		   tst-array2dep.c \
+		   tst-array2dep.c tst-piemod1.c \
 		   tst-execstack-mod.c tst-dlmodcount.c \
 		   check-textrel.c dl-sysdep.h
 
@@ -160,6 +160,9 @@ tests-nodelete-yes = nodelete nodelete2
 tests-nodlopen-yes = nodlopen nodlopen2
 tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog
 endif
+ifeq (yesyes,$(have-fpie)$(build-shared))
+tests: $(objpfx)tst-pie1.out
+endif
 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
 		testobj1_1 failobj constload2 constload3 unloadmod \
 		dep1 dep2 dep3 dep4 $(modules-vis-$(have-protected)) \
@@ -185,6 +188,9 @@ modules-names = testobj1 testobj2 testob
 ifeq (yes,$(have-initfini-array))
 modules-names += tst-array2dep
 endif
+ifeq (yesyes,$(have-fpie)$(build-shared))
+modules-names += tst-piemod1
+endif
 modules-vis-yes = vismod1 vismod2 vismod3
 modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4 \
 		       nodel2mod1 nodel2mod2 nodel2mod3
@@ -705,6 +711,25 @@ $(objpfx)tst-array4.out: $(objpfx)tst-ar
 	  $< > $@
 	cmp $@ tst-array4.exp > /dev/null
 
+ifeq (yesyes,$(have-fpie)$(build-shared))
+CFLAGS-tst-pie1.c += -fpie
+
+$(objpfx)tst-pie1.out: $(objpfx)tst-pie1
+	$(elf-objpfx)$(rtld-installed-name) \
+	  --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
+	  $< > $@
+
+$(objpfx)tst-pie1: $(objpfx)tst-pie1.o $(objpfx)tst-piemod1.so
+	$(LINK.o) -pie -Wl,-O1 \
+	  $(sysdep-LDFLAGS) $(config-LDFLAGS) \
+	  $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
+	  $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
+	  $(LDFLAGS) $(LDFLAGS-$(@F)) \
+	  -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
+	  -o $@ $(objpfx)tst-pie1.o $(objpfx)tst-piemod1.so \
+	  $(common-objpfx)libc_nonshared.a
+endif
+
 check-textrel-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
 $(objpfx)check-textrel: check-textrel.c
 	$(native-compile)
--- libc/elf/tst-piemod1.c.jj	2004-07-15 14:37:41.000000000 +0200
+++ libc/elf/tst-piemod1.c	2004-07-15 14:37:41.000000000 +0200
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int
+foo (void)
+{
+  return 21;
+}
+
+int
+main (void)
+{
+  int val = foo ();
+  if (val != 34)
+    {
+      printf ("foo () returned %d\n", val);
+      return 1;
+    }
+
+  return 0;
+}

	Jakub

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

* Re: [PATCH] Allow main to come from a shared library for PIE [BZ #262]
  2004-07-15 12:48 [PATCH] Allow main to come from a shared library for PIE [BZ #262] Jakub Jelinek
@ 2004-07-15 22:02 ` Roland McGrath
  2004-07-15 22:05   ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Roland McGrath @ 2004-07-15 22:02 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers

> +ifeq (yesyes,$(have-fpie)$(build-shared))
> +tests: $(objpfx)tst-pie1.out
> +endif

This should be tests += tst-pie1.

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

* Re: [PATCH] Allow main to come from a shared library for PIE [BZ #262]
  2004-07-15 22:02 ` Roland McGrath
@ 2004-07-15 22:05   ` Jakub Jelinek
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2004-07-15 22:05 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Ulrich Drepper, Glibc hackers

On Thu, Jul 15, 2004 at 03:02:45PM -0700, Roland McGrath wrote:
> > +ifeq (yesyes,$(have-fpie)$(build-shared))
> > +tests: $(objpfx)tst-pie1.out
> > +endif
> 
> This should be tests += tst-pie1.

No, when it is tests += tst-pie1, the elf/Makefile
$(objpfx)/tst-pie1 rule is overriding the default one.
I used tests += tst-pie1 initially but changed it afterwards.
Maybe if we have more PIE tests in the future the Makefiles could have some
common rule how to build them, but for one test I think what the patch does
is enough.

	Jakub

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

end of thread, other threads:[~2004-07-15 22:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-15 12:48 [PATCH] Allow main to come from a shared library for PIE [BZ #262] Jakub Jelinek
2004-07-15 22:02 ` Roland McGrath
2004-07-15 22:05   ` Jakub Jelinek

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