diff mbox

libgo patch committed: Don't refer to _end

Message ID CAOyqgcVdWUDHPDMJ1Rukq0DNPZuozyXzFdFYfVTeGuRLxQqMsQ@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Feb. 9, 2016, 12:34 a.m. UTC
In PR 69357 Richi points out that the libgo shared library refers to
_end, which doesn't make sense since the shared library itself will
have an _end symbol.  This patch changes the code to refer to the main
programs _end symbol, if it is available.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 233156)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-91833164072078a3fde7e9b05641ec3ed4a2f5d0
+2ef5f1ca449b5cf07dbbd7b13a50910fb5567372
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/go-main.c
===================================================================
--- libgo/runtime/go-main.c	(revision 232239)
+++ libgo/runtime/go-main.c	(working copy)
@@ -30,6 +30,11 @@ 
 
 extern char **environ;
 
+/* A copy of _end that a shared library can reasonably refer to.  */
+uintptr __go_end;
+
+extern byte _end[];
+
 /* The main function.  */
 
 int
@@ -41,6 +46,7 @@  main (int argc, char **argv)
     return 0;
   runtime_isstarted = true;
 
+  __go_end = (uintptr)_end;
   runtime_check ();
   runtime_args (argc, (byte **) argv);
   runtime_osinit ();
Index: libgo/runtime/malloc.goc
===================================================================
--- libgo/runtime/malloc.goc	(revision 232239)
+++ libgo/runtime/malloc.goc	(working copy)
@@ -505,7 +505,8 @@  runtime_mallocinit(void)
 {
 	byte *p, *p1;
 	uintptr arena_size, bitmap_size, spans_size, p_size;
-	extern byte _end[];
+	uintptr *pend;
+	uintptr end;
 	uintptr limit;
 	uint64 i;
 	bool reserved;
@@ -613,7 +614,12 @@  runtime_mallocinit(void)
 		// So adjust it upward a little bit ourselves: 1/4 MB to get
 		// away from the running binary image and then round up
 		// to a MB boundary.
-		p = (byte*)ROUND((uintptr)_end + (1<<18), 1<<20);
+
+		end = 0;
+		pend = &__go_end;
+		if(pend != nil)
+			end = *pend;
+		p = (byte*)ROUND(end + (1<<18), 1<<20);
 		p_size = bitmap_size + spans_size + arena_size + PageSize;
 		p = runtime_SysReserve(p, p_size, &reserved);
 		if(p == nil)
Index: libgo/runtime/runtime.h
===================================================================
--- libgo/runtime/runtime.h	(revision 233110)
+++ libgo/runtime/runtime.h	(working copy)
@@ -863,3 +863,4 @@  extern void _cgo_notify_runtime_init_don
 extern _Bool runtime_iscgo;
 extern _Bool runtime_cgoHasExtraM;
 extern Hchan *runtime_main_init_done;
+extern uintptr __go_end __attribute__ ((weak));