CVS commit: src/lib/csu/common

2018-12-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 28 20:12:35 UTC 2018

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Re-do previous (always make available preinit/initarray/finiarray), with
less disruption.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.22 src/lib/csu/common/crt0-common.c:1.23
--- src/lib/csu/common/crt0-common.c:1.22	Fri Dec 28 13:17:11 2018
+++ src/lib/csu/common/crt0-common.c	Fri Dec 28 15:12:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.22 2018/12/28 18:17:11 christos Exp $ */
+/* $NetBSD: crt0-common.c,v 1.23 2018/12/28 20:12:35 christos Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: crt0-common.c,v 1.22 2018/12/28 18:17:11 christos Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.23 2018/12/28 20:12:35 christos Exp $");
 
 #include 
 #include 
@@ -48,9 +48,8 @@ __RCSID("$NetBSD: crt0-common.c,v 1.22 2
 
 extern int main(int, char **, char **);
 
-#ifdef HAVE_INITFINI_ARRAY
 typedef void (*fptr_t)(void);
-#else
+#ifndef HAVE_INITFINI_ARRAY
 extern void	_init(void);
 extern void	_fini(void);
 #endif
@@ -87,7 +86,6 @@ do {		\
 	_exit(1);\
 } while (0)
 
-#ifdef HAVE_INITFINI_ARRAY
 /*
  * If we are using INIT_ARRAY/FINI_ARRAY and we are linked statically,
  * we have to process these instead of relying on RTLD to do it for us.
@@ -111,7 +109,7 @@ _preinit(void)
 }
 
 static inline void
-_init(void)
+_initarray(void)
 {
 	for (const fptr_t *f = __init_array_start; f < __init_array_end; f++) {
 		(*f)();
@@ -119,13 +117,12 @@ _init(void)
 }
 
 static void
-_fini(void)
+_finiarray(void)
 {
 	for (const fptr_t *f = __fini_array_start; f < __fini_array_end; f++) {
 		(*f)();
 	}
 }
-#endif /* HAVE_INITFINI_ARRAY */
 
 #if defined(__x86_64__) || defined(__powerpc__) || defined(__sparc__)
 #define HAS_IPLTA
@@ -327,17 +324,20 @@ ___start(void (*cleanup)(void),			/* fro
 #endif
 	}
 
-#ifdef HAVE_INITFINI_ARRAY
 	_preinit();
-#endif
 
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)&__eprol, (u_long)&__etext);
 #endif
 
+	atexit(_finiarray);
+	_initarray();
+
+#ifndef HAVE_INITFINI_ARRAY
 	atexit(_fini);
 	_init();
+#endif
 
 	exit(main(ps_strings->ps_nargvstr, ps_strings->ps_argvstr, environ));
 }



CVS commit: src/lib/csu/common

2018-12-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 28 13:53:17 UTC 2018

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
Avoid duplicate definitions on arm (reported by kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.15 src/lib/csu/common/crtbegin.c:1.16
--- src/lib/csu/common/crtbegin.c:1.15	Thu Dec 27 14:32:32 2018
+++ src/lib/csu/common/crtbegin.c	Fri Dec 28 08:53:17 2018
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: crtbegin.c,v 1.15 2018/12/27 19:32:32 christos Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.16 2018/12/28 13:53:17 christos Exp $");
 
 #include "crtbegin.h"
 
@@ -38,12 +38,14 @@ __dso_hidden const fptr_t __JCR_LIST__[0
 __weakref_visible void Jv_RegisterClasses(const fptr_t *)
 	__weak_reference(_Jv_RegisterClasses);
 
+#if !defined(HAVE_INITFINI_ARRAY)
 extern __dso_hidden const fptr_t __CTOR_LIST__start __asm("__CTOR_LIST__");
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
 	(fptr_t) -1,
 };
 __dso_hidden extern const fptr_t __CTOR_LIST_END__[];
+#endif
 
 #ifdef SHARED
 __dso_hidden void *__dso_handle = &__dso_handle;



CVS commit: src/lib/csu/common

2018-12-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec 27 19:32:32 UTC 2018

Modified Files:
src/lib/csu/common: crt0-common.c crtbegin.c

Log Message:
Allow both array and non-array constructors for transition.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/csu/common/crt0-common.c
cvs rdiff -u -r1.14 -r1.15 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.20 src/lib/csu/common/crt0-common.c:1.21
--- src/lib/csu/common/crt0-common.c:1.20	Mon Nov 26 12:37:46 2018
+++ src/lib/csu/common/crt0-common.c	Thu Dec 27 14:32:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.20 2018/11/26 17:37:46 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.21 2018/12/27 19:32:32 christos Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: crt0-common.c,v 1.20 2018/11/26 17:37:46 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.21 2018/12/27 19:32:32 christos Exp $");
 
 #include 
 #include 
@@ -50,10 +50,9 @@ extern int main(int, char **, char **);
 
 #ifdef HAVE_INITFINI_ARRAY
 typedef void (*fptr_t)(void);
-#else
+#endif
 extern void	_init(void);
 extern void	_fini(void);
-#endif
 extern void	_libc_init(void);
 
 /*
@@ -111,7 +110,7 @@ _preinit(void)
 }
 
 static inline void
-_init(void)
+_initarray(void)
 {
 	for (const fptr_t *f = __init_array_start; f < __init_array_end; f++) {
 		(*f)();
@@ -119,7 +118,7 @@ _init(void)
 }
 
 static void
-_fini(void)
+_finiarray(void)
 {
 	for (const fptr_t *f = __fini_array_start; f < __fini_array_end; f++) {
 		(*f)();
@@ -337,6 +336,10 @@ ___start(void (*cleanup)(void),			/* fro
 #endif
 
 	atexit(_fini);
+#ifdef HAVE_INITFINI_ARRAY
+	atexit(_finiarray);
+	_initarray();
+#endif
 	_init();
 
 	exit(main(ps_strings->ps_nargvstr, ps_strings->ps_argvstr, environ));

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.14 src/lib/csu/common/crtbegin.c:1.15
--- src/lib/csu/common/crtbegin.c:1.14	Tue Jul 18 10:34:19 2017
+++ src/lib/csu/common/crtbegin.c	Thu Dec 27 14:32:32 2018
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: crtbegin.c,v 1.14 2017/07/18 14:34:19 joerg Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.15 2018/12/27 19:32:32 christos Exp $");
 
 #include "crtbegin.h"
 
@@ -38,14 +38,12 @@ __dso_hidden const fptr_t __JCR_LIST__[0
 __weakref_visible void Jv_RegisterClasses(const fptr_t *)
 	__weak_reference(_Jv_RegisterClasses);
 
-#if !defined(HAVE_INITFINI_ARRAY)
 extern __dso_hidden const fptr_t __CTOR_LIST__start __asm("__CTOR_LIST__");
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
 	(fptr_t) -1,
 };
 __dso_hidden extern const fptr_t __CTOR_LIST_END__[];
-#endif
 
 #ifdef SHARED
 __dso_hidden void *__dso_handle = &__dso_handle;



CVS commit: src/lib/csu/common

2018-07-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Jul 13 01:00:17 UTC 2018

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
i386/amd64 build fix.   Fix "possibly used uninitialized" from gcc.
These changes should make no practical effect - but because external
data is being examined, it would be possible to contrive a situation
(perhaps) where uninit'd vars could actually be used (unless the format
has been checked elsewhere earlier - I did not look ... we have to
appease gcc anyway).

Joerg: Please review (& fix)


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.18 src/lib/csu/common/crt0-common.c:1.19
--- src/lib/csu/common/crt0-common.c:1.18	Thu Jul 12 21:36:45 2018
+++ src/lib/csu/common/crt0-common.c	Fri Jul 13 01:00:17 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.18 2018/07/12 21:36:45 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.19 2018/07/13 01:00:17 kre Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: crt0-common.c,v 1.18 2018/07/12 21:36:45 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.19 2018/07/13 01:00:17 kre Exp $");
 
 #include 
 #include 
@@ -214,9 +214,9 @@ relocate_self(struct ps_strings *ps_stri
 {
 	AuxInfo *aux = (AuxInfo *)(ps_strings->ps_argvstr + ps_strings->ps_nargvstr +
 	ps_strings->ps_nenvstr + 2);
-	uintptr_t relocbase;
-	const Elf_Phdr *phdr;
-	Elf_Half phnum;
+	uintptr_t relocbase = (uintptr_t)~0U;
+	const Elf_Phdr *phdr = NULL;
+	Elf_Half phnum = (Elf_Half)~0;
 
 	for (; aux->a_type != AT_NULL; ++aux) {
 		switch (aux->a_type) {
@@ -232,7 +232,11 @@ relocate_self(struct ps_strings *ps_stri
 			break;
 		}
 	}
-	const Elf_Phdr *phlimit = phdr + phnum, *dynphdr;
+
+	if (phdr == NULL || phnum == (Elf_Half)~0)
+		return;
+
+	const Elf_Phdr *phlimit = phdr + phnum, *dynphdr = NULL;
 
 	for (; phdr < phlimit; ++phdr) {
 		if (phdr->p_type == PT_DYNAMIC)
@@ -240,6 +244,9 @@ relocate_self(struct ps_strings *ps_stri
 		if (phdr->p_type == PT_PHDR)
 			relocbase = (uintptr_t)phdr - phdr->p_vaddr;
 	}
+	if (dynphdr == NULL || relocbase == (uintptr_t)~0U)
+		return;
+
 	Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase);
 
 	const REL_TYPE *relocs = 0, *relocslim;



CVS commit: src/lib/csu/common

2018-07-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Jul 12 21:36:46 UTC 2018

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Add static PIE support for i386 and AMD64.

The basic glue works with mininal changes for other architectures as
well, but those require linker changes first to avoid leaking dynamic
relocations into the binary.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.17 src/lib/csu/common/crt0-common.c:1.18
--- src/lib/csu/common/crt0-common.c:1.17	Thu Jul 12 21:35:12 2018
+++ src/lib/csu/common/crt0-common.c	Thu Jul 12 21:36:45 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.17 2018/07/12 21:35:12 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.18 2018/07/12 21:36:45 joerg Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: crt0-common.c,v 1.17 2018/07/12 21:35:12 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.18 2018/07/12 21:36:45 joerg Exp $");
 
 #include 
 #include 
@@ -192,11 +192,103 @@ fix_iplt(void)
 }
 #endif
 
+#if defined(__x86_64__) || defined(__i386__)
+#  define HAS_RELOCATE_SELF
+#  if defined(__x86_64__)
+#  define RELA
+#  define REL_TAG DT_RELA
+#  define RELSZ_TAG DT_RELASZ
+#  define REL_TYPE Elf_Rela
+#  else
+#  define REL_TAG DT_REL
+#  define RELSZ_TAG DT_RELSZ
+#  define REL_TYPE Elf_Rel
+#  endif
+
+#include 
+
+static void relocate_self(struct ps_strings *) __noinline;
+
+static void
+relocate_self(struct ps_strings *ps_strings)
+{
+	AuxInfo *aux = (AuxInfo *)(ps_strings->ps_argvstr + ps_strings->ps_nargvstr +
+	ps_strings->ps_nenvstr + 2);
+	uintptr_t relocbase;
+	const Elf_Phdr *phdr;
+	Elf_Half phnum;
+
+	for (; aux->a_type != AT_NULL; ++aux) {
+		switch (aux->a_type) {
+		case AT_BASE:
+			if (aux->a_v)
+return;
+			break;
+		case AT_PHDR:
+			phdr = (void *)aux->a_v;
+			break;
+		case AT_PHNUM:
+			phnum = (Elf_Half)aux->a_v;
+			break;
+		}
+	}
+	const Elf_Phdr *phlimit = phdr + phnum, *dynphdr;
+
+	for (; phdr < phlimit; ++phdr) {
+		if (phdr->p_type == PT_DYNAMIC)
+			dynphdr = phdr;
+		if (phdr->p_type == PT_PHDR)
+			relocbase = (uintptr_t)phdr - phdr->p_vaddr;
+	}
+	Elf_Dyn *dynp = (Elf_Dyn *)((uint8_t *)dynphdr->p_vaddr + relocbase);
+
+	const REL_TYPE *relocs = 0, *relocslim;
+	Elf_Addr relocssz = 0;
+
+	for (; dynp->d_tag != DT_NULL; dynp++) {
+		switch (dynp->d_tag) {
+		case REL_TAG:
+			relocs =
+			(const REL_TYPE *)(relocbase + dynp->d_un.d_ptr);
+			break;
+		case RELSZ_TAG:
+			relocssz = dynp->d_un.d_val;
+			break;
+		}
+	}
+	relocslim = (const REL_TYPE *)((const uint8_t *)relocs + relocssz);
+	for (; relocs < relocslim; ++relocs) {
+		Elf_Addr *where;
+
+		where = (Elf_Addr *)(relocbase + relocs->r_offset);
+
+		switch (ELF_R_TYPE(relocs->r_info)) {
+		case R_TYPE(RELATIVE):  /* word64 B + A */
+#ifdef RELA
+			*where = (Elf_Addr)(relocbase + relocs->r_addend);
+#else
+			*where += (Elf_Addr)relocbase;
+#endif
+			break;
+#ifdef IFUNC_RELOCATION
+		case IFUNC_RELOCATION:
+			break;
+#endif
+		default:
+			abort();
+		}
+	}
+}
+#endif
+
 void
 ___start(void (*cleanup)(void),			/* from shared loader */
 const Obj_Entry *obj,			/* from shared loader */
 struct ps_strings *ps_strings)
 {
+#if defined(HAS_RELOCATE_SELF)
+	relocate_self(ps_strings);
+#endif
 
 	if (ps_strings == NULL)
 		_FATAL("ps_strings missing\n");



CVS commit: src/lib/csu/common

2018-07-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Jul 12 21:35:12 UTC 2018

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
_DYNAMIC is present for static PIE as well, so loosen rtld check.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.16 src/lib/csu/common/crt0-common.c:1.17
--- src/lib/csu/common/crt0-common.c:1.16	Thu Mar 29 13:23:39 2018
+++ src/lib/csu/common/crt0-common.c	Thu Jul 12 21:35:12 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.16 2018/03/29 13:23:39 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.17 2018/07/12 21:35:12 joerg Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: crt0-common.c,v 1.16 2018/03/29 13:23:39 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.17 2018/07/12 21:35:12 joerg Exp $");
 
 #include 
 #include 
@@ -215,9 +215,7 @@ ___start(void (*cleanup)(void),			/* fro
 		__progname = empty_string;
 	}
 
-	if (_DYNAMIC != NULL) {
-		if (obj == NULL)
-			_FATAL("NULL Obj_Entry pointer in GOT\n");
+	if (_DYNAMIC != NULL && obj != NULL) {
 		if (obj->magic != RTLD_MAGIC)
 			_FATAL("Corrupt Obj_Entry pointer in GOT\n");
 		if (obj->version != RTLD_VERSION)



CVS commit: src/lib/csu/common

2016-06-29 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jun 29 11:16:47 UTC 2016

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
For some mind-boogling reasons, GCC 5.4 believes that a weak reference
cannot alias with an extern. While this is clearly bogus, avoid yet
another alias handling bug and use strong aliases. It's actually
slightly simpler, too.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.12 src/lib/csu/common/crtbegin.c:1.13
--- src/lib/csu/common/crtbegin.c:1.12	Tue Jun  7 12:07:35 2016
+++ src/lib/csu/common/crtbegin.c	Wed Jun 29 11:16:47 2016
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: crtbegin.c,v 1.12 2016/06/07 12:07:35 joerg Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.13 2016/06/29 11:16:47 joerg Exp $");
 
 #include "crtbegin.h"
 
@@ -39,8 +39,7 @@ __weakref_visible void Jv_RegisterClasse
 	__weak_reference(_Jv_RegisterClasses);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-__weakref_visible const fptr_t __CTOR_LIST__start
-__weak_reference(__CTOR_LIST__);
+extern __dso_hidden const fptr_t __CTOR_LIST__start __asm("__CTOR_LIST__");
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
 	(fptr_t) -1,
@@ -101,8 +100,7 @@ __do_global_ctors_aux(void)
 
 #if !defined(__ARM_EABI__) || defined(SHARED) || defined(__ARM_DWARF_EH__)
 #if !defined(HAVE_INITFINI_ARRAY)
-__weakref_visible const fptr_t __DTOR_LIST__start
-__weak_reference(__DTOR_LIST__);
+extern __dso_hidden const fptr_t __DTOR_LIST__start __asm("__DTOR_LIST__");
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = {
 	(fptr_t) -1,



CVS commit: src/lib/csu/common

2016-06-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Jun  7 12:07:35 UTC 2016

Modified Files:
src/lib/csu/common: crt0-common.c crtbegin.c

Log Message:
Fun fact of the weak: a weak reference doesn't have visibility attached.
As such, reorganize the start/end references to use a weak reference
only, if we use it to remove size knowledge. Otherwise use weak
external declarations.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/csu/common/crt0-common.c
cvs rdiff -u -r1.11 -r1.12 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.13 src/lib/csu/common/crt0-common.c:1.14
--- src/lib/csu/common/crt0-common.c:1.13	Thu Jan 31 22:24:25 2013
+++ src/lib/csu/common/crt0-common.c	Tue Jun  7 12:07:35 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.13 2013/01/31 22:24:25 matt Exp $ */
+/* $NetBSD: crt0-common.c,v 1.14 2016/06/07 12:07:35 joerg Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: crt0-common.c,v 1.13 2013/01/31 22:24:25 matt Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.14 2016/06/07 12:07:35 joerg Exp $");
 
 #include 
 #include 
@@ -95,23 +95,17 @@ do {		\
  * Since we don't need .init or .fini sections, just code them in C
  * to make life easier.
  */
-__weakref_visible const fptr_t preinit_array_start[1]
-__weak_reference(__preinit_array_start);
-__weakref_visible const fptr_t preinit_array_end[1]
-__weak_reference(__preinit_array_end);
-__weakref_visible const fptr_t init_array_start[1]
-__weak_reference(__init_array_start);
-__weakref_visible const fptr_t init_array_end[1]
-__weak_reference(__init_array_end);
-__weakref_visible const fptr_t fini_array_start[1]
-__weak_reference(__fini_array_start);
-__weakref_visible const fptr_t fini_array_end[1]
-__weak_reference(__fini_array_end);
+extern const fptr_t __preinit_array_start[] __dso_hidden;
+extern const fptr_t __preinit_array_end[] __dso_hidden __weak;
+extern const fptr_t __init_array_start[] __dso_hidden;
+extern const fptr_t __init_array_end[] __dso_hidden __weak;
+extern const fptr_t __fini_array_start[] __dso_hidden;
+extern const fptr_t __fini_array_end[] __dso_hidden __weak;
 
 static inline void
 _preinit(void)
 {
-	for (const fptr_t *f = preinit_array_start; f < preinit_array_end; f++) {
+	for (const fptr_t *f = __preinit_array_start; f < __preinit_array_end; f++) {
 		(*f)();
 	}
 }
@@ -119,7 +113,7 @@ _preinit(void)
 static inline void
 _init(void)
 {
-	for (const fptr_t *f = init_array_start; f < init_array_end; f++) {
+	for (const fptr_t *f = __init_array_start; f < __init_array_end; f++) {
 		(*f)();
 	}
 }
@@ -127,7 +121,7 @@ _init(void)
 static void
 _fini(void)
 {
-	for (const fptr_t *f = fini_array_start; f < fini_array_end; f++) {
+	for (const fptr_t *f = __fini_array_start; f < __fini_array_end; f++) {
 		(*f)();
 	}
 }

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.11 src/lib/csu/common/crtbegin.c:1.12
--- src/lib/csu/common/crtbegin.c:1.11	Sun Jun  5 00:43:39 2016
+++ src/lib/csu/common/crtbegin.c	Tue Jun  7 12:07:35 2016
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: crtbegin.c,v 1.11 2016/06/05 00:43:39 joerg Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.12 2016/06/07 12:07:35 joerg Exp $");
 
 #include "crtbegin.h"
 
@@ -41,8 +41,6 @@ __weakref_visible void Jv_RegisterClasse
 #if !defined(HAVE_INITFINI_ARRAY)
 __weakref_visible const fptr_t __CTOR_LIST__start
 __weak_reference(__CTOR_LIST__);
-__weakref_visible const fptr_t __CTOR_LIST__end
-__weak_reference(__CTOR_LIST_END__);
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
 	(fptr_t) -1,
@@ -95,7 +93,7 @@ __do_global_ctors_aux(void)
 		Jv_RegisterClasses(__JCR_LIST__);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-	for (const fptr_t *p = &__CTOR_LIST__end; p > &__CTOR_LIST__start + 1; ) {
+	for (const fptr_t *p = __CTOR_LIST_END__; p > &__CTOR_LIST__start + 1; ) {
 		(*(*--p))();
 	}
 #endif
@@ -105,8 +103,6 @@ __do_global_ctors_aux(void)
 #if !defined(HAVE_INITFINI_ARRAY)
 __weakref_visible const fptr_t __DTOR_LIST__start
 __weak_reference(__DTOR_LIST__);
-__weakref_visible const fptr_t __DTOR_LIST__end
-__weak_reference(__DTOR_LIST_END__);
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = {
 	(fptr_t) -1,
@@ -132,7 +128,7 @@ __do_global_dtors_aux(void)
 #endif
 
 #if !defined(HAVE_INITFINI_ARRAY)
-	for (const fptr_t *p = &__DTOR_LIST__start + 1; p < &__DTOR_LIST__end; ) {
+	for (const fptr_t *p = &__DTOR_LIST__start + 1; p < __DTOR_LIST_END__; ) {
 		(*(*p++))();
 	}
 #endif



CVS commit: src/lib/csu/common

2016-06-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Jun  5 00:43:39 UTC 2016

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
Make older GCC and Clang happy and use weak references to the elements,
not declared as arrays.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.10 src/lib/csu/common/crtbegin.c:1.11
--- src/lib/csu/common/crtbegin.c:1.10	Wed Jun  1 21:21:55 2016
+++ src/lib/csu/common/crtbegin.c	Sun Jun  5 00:43:39 2016
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: crtbegin.c,v 1.10 2016/06/01 21:21:55 joerg Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.11 2016/06/05 00:43:39 joerg Exp $");
 
 #include "crtbegin.h"
 
@@ -39,9 +39,9 @@ __weakref_visible void Jv_RegisterClasse
 	__weak_reference(_Jv_RegisterClasses);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-__weakref_visible const fptr_t __CTOR_LIST__start[]
+__weakref_visible const fptr_t __CTOR_LIST__start
 __weak_reference(__CTOR_LIST__);
-__weakref_visible const fptr_t __CTOR_LIST__end[]
+__weakref_visible const fptr_t __CTOR_LIST__end
 __weak_reference(__CTOR_LIST_END__);
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
@@ -95,7 +95,7 @@ __do_global_ctors_aux(void)
 		Jv_RegisterClasses(__JCR_LIST__);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-	for (const fptr_t *p = __CTOR_LIST__end; p > __CTOR_LIST__start + 1; ) {
+	for (const fptr_t *p = &__CTOR_LIST__end; p > &__CTOR_LIST__start + 1; ) {
 		(*(*--p))();
 	}
 #endif
@@ -103,9 +103,9 @@ __do_global_ctors_aux(void)
 
 #if !defined(__ARM_EABI__) || defined(SHARED) || defined(__ARM_DWARF_EH__)
 #if !defined(HAVE_INITFINI_ARRAY)
-__weakref_visible const fptr_t __DTOR_LIST__start[]
+__weakref_visible const fptr_t __DTOR_LIST__start
 __weak_reference(__DTOR_LIST__);
-__weakref_visible const fptr_t __DTOR_LIST__end[]
+__weakref_visible const fptr_t __DTOR_LIST__end
 __weak_reference(__DTOR_LIST_END__);
 
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = {
@@ -132,7 +132,7 @@ __do_global_dtors_aux(void)
 #endif
 
 #if !defined(HAVE_INITFINI_ARRAY)
-	for (const fptr_t *p = __DTOR_LIST__start + 1; p < __DTOR_LIST__end; ) {
+	for (const fptr_t *p = &__DTOR_LIST__start + 1; p < &__DTOR_LIST__end; ) {
 		(*(*p++))();
 	}
 #endif



CVS commit: src/lib/csu/common

2016-06-01 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jun  1 21:21:55 UTC 2016

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
PR toolchain/51121:
__CTOR_LIST__ and __CTOR_LIST_END__ are logically the same object, but
due to the start marker, the former has to be declared as array of fixed
size. Newer GCC versions take the liberty of exploiting the UB of
accessing global objects past the end to unconditionally load zero
values in that case. Two fixes are possible:
(1) Pruning via inline assembler as done by GCC's own CRT copy.
(2) Pruning via weak references as done for linker sets.
Since the second part is known and required to work anyway, prefer this
approach. In theory, the labels could be replaced completely, except
that GNU as doesn't provide start/end symbols for sections containing
dots.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.9 src/lib/csu/common/crtbegin.c:1.10
--- src/lib/csu/common/crtbegin.c:1.9	Tue May  6 16:02:10 2014
+++ src/lib/csu/common/crtbegin.c	Wed Jun  1 21:21:55 2016
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: crtbegin.c,v 1.9 2014/05/06 16:02:10 joerg Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.10 2016/06/01 21:21:55 joerg Exp $");
 
 #include "crtbegin.h"
 
@@ -39,6 +39,11 @@ __weakref_visible void Jv_RegisterClasse
 	__weak_reference(_Jv_RegisterClasses);
 
 #if !defined(HAVE_INITFINI_ARRAY)
+__weakref_visible const fptr_t __CTOR_LIST__start[]
+__weak_reference(__CTOR_LIST__);
+__weakref_visible const fptr_t __CTOR_LIST__end[]
+__weak_reference(__CTOR_LIST_END__);
+
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
 	(fptr_t) -1,
 };
@@ -90,7 +95,7 @@ __do_global_ctors_aux(void)
 		Jv_RegisterClasses(__JCR_LIST__);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-	for (const fptr_t *p = __CTOR_LIST_END__; p > __CTOR_LIST__ + 1; ) {
+	for (const fptr_t *p = __CTOR_LIST__end; p > __CTOR_LIST__start + 1; ) {
 		(*(*--p))();
 	}
 #endif
@@ -98,6 +103,11 @@ __do_global_ctors_aux(void)
 
 #if !defined(__ARM_EABI__) || defined(SHARED) || defined(__ARM_DWARF_EH__)
 #if !defined(HAVE_INITFINI_ARRAY)
+__weakref_visible const fptr_t __DTOR_LIST__start[]
+__weak_reference(__DTOR_LIST__);
+__weakref_visible const fptr_t __DTOR_LIST__end[]
+__weak_reference(__DTOR_LIST_END__);
+
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = {
 	(fptr_t) -1,
 };
@@ -122,7 +132,7 @@ __do_global_dtors_aux(void)
 #endif
 
 #if !defined(HAVE_INITFINI_ARRAY)
-	for (const fptr_t *p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__; ) {
+	for (const fptr_t *p = __DTOR_LIST__start + 1; p < __DTOR_LIST__end; ) {
 		(*(*p++))();
 	}
 #endif



CVS commit: src/lib/csu/common

2016-06-01 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jun  1 21:24:55 UTC 2016

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Revert -O1 hack for GCC 5.3, replaced by workaround in the code.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.31 src/lib/csu/common/Makefile.inc:1.32
--- src/lib/csu/common/Makefile.inc:1.31	Tue May 10 10:23:09 2016
+++ src/lib/csu/common/Makefile.inc	Wed Jun  1 21:24:55 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.31 2016/05/10 10:23:09 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.32 2016/06/01 21:24:55 joerg Exp $
 
 .include 
 
@@ -17,14 +17,6 @@ OBJS+=		sysident.o
 .if ${MKPIC} == "yes"
 OBJS+=		crtbeginS.o
 CFLAGS.crtbegin.c+= -fPIE
-# XXXGCC5 - GCC 5 miscompiles crtbeginS.c on many platforms.  on SPARC it
-# XXXGCC5   emits "clr %g1; call %g1", which is effectively jumping to zero.
-. if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
- !exists(${ARCHDIR}/crtbegin.S)
-CFLAGS.crt0-common.c+=	-O1
-CFLAGS.crtbeginS.c+=	-O1
-CFLAGS.crtbegin.c+=	-O1
-. endif
 .endif
 
 .if ${MACHINE_ARCH} == "alpha"



CVS commit: src/lib/csu/common

2016-05-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 10 10:23:09 UTC 2016

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
We need the -O1 hack (for gcc 5.3) for crtbegin.c as well.
Works around PR toolchain/51121.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.30 src/lib/csu/common/Makefile.inc:1.31
--- src/lib/csu/common/Makefile.inc:1.30	Sun May  1 07:25:46 2016
+++ src/lib/csu/common/Makefile.inc	Tue May 10 10:23:09 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.30 2016/05/01 07:25:46 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.31 2016/05/10 10:23:09 martin Exp $
 
 .include 
 
@@ -23,6 +23,7 @@ CFLAGS.crtbegin.c+= -fPIE
  !exists(${ARCHDIR}/crtbegin.S)
 CFLAGS.crt0-common.c+=	-O1
 CFLAGS.crtbeginS.c+=	-O1
+CFLAGS.crtbegin.c+=	-O1
 . endif
 .endif
 



CVS commit: src/lib/csu/common

2016-05-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  1 08:33:14 UTC 2016

Modified Files:
src/lib/csu/common: compident.S

Log Message:
Change section flags to "MG" and put it into comdat.
Makes new binutils happy.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/csu/common/compident.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/compident.S
diff -u src/lib/csu/common/compident.S:1.3 src/lib/csu/common/compident.S:1.4
--- src/lib/csu/common/compident.S:1.3	Wed May 14 14:59:14 2014
+++ src/lib/csu/common/compident.S	Sun May  1 08:33:14 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: compident.S,v 1.3 2014/05/14 14:59:14 joerg Exp $ */
+/* $NetBSD: compident.S,v 1.4 2016/05/01 08:33:14 martin Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
 
 #include "sysident_assym.h"
 
-	.section .note.netbsd.mcmodel,"aM",@note,3*4+CONTENTLENGTH+ELF_NOTE_MCMODEL_NAMESZ+1
+	.section .note.netbsd.mcmodel,"MG",@note,3*4+CONTENTLENGTH+ELF_NOTE_MCMODEL_NAMESZ+1,comdat
 	.p2align 2
 
 	.long	ELF_NOTE_MCMODEL_NAMESZ



CVS commit: src/lib/csu/common

2016-05-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  1 07:25:46 UTC 2016

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Revert previous (fallout is more subtle but there).
Rework the conditionon so it depends on .S existence instead of an arch
list.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.29 src/lib/csu/common/Makefile.inc:1.30
--- src/lib/csu/common/Makefile.inc:1.29	Sat Apr 30 13:12:13 2016
+++ src/lib/csu/common/Makefile.inc	Sun May  1 07:25:46 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.29 2016/04/30 13:12:13 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.30 2016/05/01 07:25:46 martin Exp $
 
 .include 
 
@@ -20,8 +20,7 @@ CFLAGS.crtbegin.c+= -fPIE
 # XXXGCC5 - GCC 5 miscompiles crtbeginS.c on many platforms.  on SPARC it
 # XXXGCC5   emits "clr %g1; call %g1", which is effectively jumping to zero.
 . if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
- ${CSU_MACHINE_ARCH} != "i386" && ${CSU_MACHINE_ARCH} != "amd64" && \
- ${CSU_MACHINE_ARCH} != "sparc64"
+ !exists(${ARCHDIR}/crtbegin.S)
 CFLAGS.crt0-common.c+=	-O1
 CFLAGS.crtbeginS.c+=	-O1
 . endif



CVS commit: src/lib/csu/common

2016-04-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Apr 30 13:12:13 UTC 2016

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Gcc 5.3 seems to do fine compiling this for sparc64, so exclude it
from the -O1 hack


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.28 src/lib/csu/common/Makefile.inc:1.29
--- src/lib/csu/common/Makefile.inc:1.28	Mon Apr  4 18:29:07 2016
+++ src/lib/csu/common/Makefile.inc	Sat Apr 30 13:12:13 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.28 2016/04/04 18:29:07 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.29 2016/04/30 13:12:13 martin Exp $
 
 .include 
 
@@ -20,7 +20,8 @@ CFLAGS.crtbegin.c+= -fPIE
 # XXXGCC5 - GCC 5 miscompiles crtbeginS.c on many platforms.  on SPARC it
 # XXXGCC5   emits "clr %g1; call %g1", which is effectively jumping to zero.
 . if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
- ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "amd64"
+ ${CSU_MACHINE_ARCH} != "i386" && ${CSU_MACHINE_ARCH} != "amd64" && \
+ ${CSU_MACHINE_ARCH} != "sparc64"
 CFLAGS.crt0-common.c+=	-O1
 CFLAGS.crtbeginS.c+=	-O1
 . endif



CVS commit: src/lib/csu/common

2016-03-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Mar 29 21:23:05 UTC 2016

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
crt0-common.c is miscompiled by gcc 5.3 on evbarm with -O2 so use -O1.  Do
this for all non-x86 arches.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.26 src/lib/csu/common/Makefile.inc:1.27
--- src/lib/csu/common/Makefile.inc:1.26	Sun Mar 27 00:03:06 2016
+++ src/lib/csu/common/Makefile.inc	Tue Mar 29 21:23:05 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.26 2016/03/27 00:03:06 mrg Exp $
+#	$NetBSD: Makefile.inc,v 1.27 2016/03/29 21:23:05 skrll Exp $
 
 .include 
 
@@ -20,6 +20,7 @@ CFLAGS.crtbegin.c+= -fPIE
 # XXXGCC5   emits "clr %g1; call %g1", which is effectively jumping to zero.
 . if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
  ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "amd64"
+CFLAGS.crt0-common.c+=	-O1
 CFLAGS.crtbeginS.c+=	-O1
 . endif
 .endif
@@ -88,7 +89,7 @@ MY_PICFLAGS=
 crt0.o: crt0.S crt0-common.c
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
-	${COMPILE.c} ${MY_PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
+	${COMPILE.c} ${CFLAGS.crt0-common.c} ${MY_PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
 	${LD} -r -o ${.TARGET}.o ${.TARGET}.S.o ${.TARGET}.c.o
 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
 	rm -f ${.TARGET}.S.o ${.TARGET}.c.o ${.TARGET}.o



CVS commit: src/lib/csu/common

2016-03-26 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar 27 00:03:06 UTC 2016

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
add a hack for GCC 5 and non-x86 platforms:

build crtbeginS.o with -O1 as GCC tries to be very smart with the
__DTOR_LIST__ as it believes it knows the size of the array at
compile time (which is not true until link time).  on SPARC and
MIPS, the result was emitting a call to 0.

technically, i believe that GCC isn't "wrong" to make this choice,
as the array is declared with a well-known initialiser size in the
crtbegin.c compilation unit, and we have noticed that the libgcc
version of this code has some hacks added, most likely to avoid
being bitten by this optimisation.

this makes sshd work for me on earm and sparc with GCC 5.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.25 src/lib/csu/common/Makefile.inc:1.26
--- src/lib/csu/common/Makefile.inc:1.25	Tue Mar  4 17:57:56 2014
+++ src/lib/csu/common/Makefile.inc	Sun Mar 27 00:03:06 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.25 2014/03/04 17:57:56 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.26 2016/03/27 00:03:06 mrg Exp $
 
 .include 
 
@@ -16,7 +16,14 @@ OBJS+=		crtbegin.o crtend.o
 .if ${MKPIC} == "yes"
 OBJS+=		crtbeginS.o
 CFLAGS.crtbegin.c+= -fPIE
+# XXXGCC5 - GCC 5 miscompiles crtbeginS.c on many platforms.  on SPARC it
+# XXXGCC5   emits "clr %g1; call %g1", which is effectively jumping to zero.
+. if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
+ ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "amd64"
+CFLAGS.crtbeginS.c+=	-O1
+. endif
 .endif
+
 .if ${MACHINE_ARCH} == "alpha"
 OBJS+=		crtfm.o
 .endif
@@ -55,7 +62,7 @@ crtbeginS.o: crtbegin.S
 .else
 crtbeginS.o: crtbegin.c crtbegin.h
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
+	${COMPILE.c} ${CFLAGS.crtbeginS.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
 	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
 	rm -f ${.TARGET}.o



CVS commit: src/lib/csu/common

2014-05-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed May 14 14:59:14 UTC 2014

Modified Files:
src/lib/csu/common: compident.S sysident.S

Log Message:
Ensure notes are properly padded to 32bit length.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/csu/common/compident.S \
src/lib/csu/common/sysident.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/compident.S
diff -u src/lib/csu/common/compident.S:1.2 src/lib/csu/common/compident.S:1.3
--- src/lib/csu/common/compident.S:1.2	Wed Feb 26 14:54:50 2014
+++ src/lib/csu/common/compident.S	Wed May 14 14:59:14 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: compident.S,v 1.2 2014/02/26 14:54:50 martin Exp $ */
+/* $NetBSD: compident.S,v 1.3 2014/05/14 14:59:14 joerg Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -63,3 +63,4 @@
 	.long	ELF_NOTE_TYPE_MCMODEL_TAG
 	.ascii	NetBSD\0\0
 	.ascii	CONTENT
+	.p2align 2
Index: src/lib/csu/common/sysident.S
diff -u src/lib/csu/common/sysident.S:1.2 src/lib/csu/common/sysident.S:1.3
--- src/lib/csu/common/sysident.S:1.2	Tue Sep 10 16:45:33 2013
+++ src/lib/csu/common/sysident.S	Wed May 14 14:59:14 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: sysident.S,v 1.2 2013/09/10 16:45:33 matt Exp $ */
+/* $NetBSD: sysident.S,v 1.3 2014/05/14 14:59:14 joerg Exp $ */
 
 /*
  * Copyright (c) 1997 Christopher G. Demetriou
@@ -85,4 +85,5 @@
 	.long	ELF_NOTE_TYPE_MARCH_TAG
 	.ascii	NetBSD\0\0
 	.asciz	ELF_NOTE_MARCH_DESC
+	.p2align 2
 #endif



CVS commit: src/lib/csu/common

2014-02-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Feb 26 14:54:51 UTC 2014

Modified Files:
src/lib/csu/common: compident.S

Log Message:
Make the .note section mergable and set proper item length.
XXX seems to be impossible to do that with gas w/o causing a (bogus)
warning - but the resulting object file is fine.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/csu/common/compident.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/compident.S
diff -u src/lib/csu/common/compident.S:1.1 src/lib/csu/common/compident.S:1.2
--- src/lib/csu/common/compident.S:1.1	Thu Nov 14 12:19:34 2013
+++ src/lib/csu/common/compident.S	Wed Feb 26 14:54:50 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: compident.S,v 1.1 2013/11/14 12:19:34 martin Exp $ */
+/* $NetBSD: compident.S,v 1.2 2014/02/26 14:54:50 martin Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
 
 #include sysident_assym.h
 
-	.section .note.netbsd.mcmodel, a
+	.section .note.netbsd.mcmodel,aM,@note,3*4+CONTENTLENGTH+ELF_NOTE_MCMODEL_NAMESZ+1
 	.p2align 2
 
 	.long	ELF_NOTE_MCMODEL_NAMESZ



CVS commit: src/lib/csu/common

2014-01-29 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Jan 29 20:57:49 UTC 2014

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
Also make sure the __CTOR_LIST__ is just aligned to a pointer boundary.
By default, mips N32 will aligned to a 64-bit boundary not 32-bit
which causes an extra NULL entry to be added.
Fix segfault on exit several people have noticed on mips N32,
caused by a jr to a NULL address.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.7 src/lib/csu/common/crtbegin.c:1.8
--- src/lib/csu/common/crtbegin.c:1.7	Wed Dec 11 06:55:24 2013
+++ src/lib/csu/common/crtbegin.c	Wed Jan 29 20:57:49 2014
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: crtbegin.c,v 1.7 2013/12/11 06:55:24 matt Exp $);
+__RCSID($NetBSD: crtbegin.c,v 1.8 2014/01/29 20:57:49 bouyer Exp $);
 
 #include crtbegin.h
 
@@ -98,7 +98,7 @@ __do_global_ctors_aux(void)
 
 #if !defined(__ARM_EABI__) || defined(SHARED)
 #if !defined(HAVE_INITFINI_ARRAY)
-__dso_hidden const fptr_t __DTOR_LIST__[] __section(.dtors) = {
+__dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(.dtors) = {
 	(fptr_t) -1,
 };
 __dso_hidden extern const fptr_t __DTOR_LIST_END__[];



CVS commit: src/lib/csu/common

2014-01-10 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sat Jan 11 00:18:15 UTC 2014

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Using ${LD} -x screws up BE arm.  Use ${OBJCOPY} ${OBJCOPYLIBFLAGS} instead
so the $a/$t/$d symbols are preserved.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.23 src/lib/csu/common/Makefile.inc:1.24
--- src/lib/csu/common/Makefile.inc:1.23	Sun Nov 17 11:16:09 2013
+++ src/lib/csu/common/Makefile.inc	Sat Jan 11 00:18:15 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.23 2013/11/17 11:16:09 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.24 2014/01/11 00:18:15 matt Exp $
 
 .include bsd.own.mk
 
@@ -42,7 +42,7 @@ crtbegin.o: crtbegin.c crtbegin.h
 	${_MKTARGET_COMPILE}
 	${COMPILE.c} ${CFLAGS.crtbegin.c} ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
@@ -57,7 +57,7 @@ crtbeginS.o: crtbegin.c crtbegin.h
 	${_MKTARGET_COMPILE}
 	${COMPILE.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
@@ -66,7 +66,7 @@ crtbeginS.o: crtbegin.c crtbegin.h
 crtend.o: crtend.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} ${ARCHDIR}/crtend.S -o ${.TARGET}.o
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
@@ -82,8 +82,9 @@ crt0.o: crt0.S crt0-common.c
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
 	${COMPILE.c} ${MY_PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.S.o ${.TARGET}.c.o
-	rm -f ${.TARGET}.S.o ${.TARGET}.c.o
+	${LD} -r -o ${.TARGET}.o ${.TARGET}.S.o ${.TARGET}.c.o
+	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
+	rm -f ${.TARGET}.S.o ${.TARGET}.c.o ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif
@@ -92,8 +93,9 @@ gcrt0.o: crt0.S crt0-common.c
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
 	${COMPILE.c} ${MY_PICFLAGS} -DMCRT0 ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.S.o ${.TARGET}.c.o
-	rm -f ${.TARGET}.S.o ${.TARGET}.c.o
+	${LD} -r -o ${.TARGET}.o ${.TARGET}.S.o ${.TARGET}.c.o
+	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
+	rm -f ${.TARGET}.S.o ${.TARGET}.c.o ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif
@@ -103,7 +105,7 @@ gcrt0.o: crt0.S crt0-common.c
 crtfm.o: crtfm.c
 	${_MKTARGET_COMPILE}
 	${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
 	rm -f ${.TARGET}.o
 .endif
 



CVS commit: src/lib/csu/common

2013-12-10 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Dec 11 06:55:25 UTC 2013

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
Make sure the __CTOR_LIST__ is just aligned to a pointer boundary.
By default, mips N32 will aligned to a 64-bit boundary not 32-bit
which causes an extra NULL entry to be added.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.6 src/lib/csu/common/crtbegin.c:1.7
--- src/lib/csu/common/crtbegin.c:1.6	Fri Nov 29 23:00:48 2013
+++ src/lib/csu/common/crtbegin.c	Wed Dec 11 06:55:24 2013
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: crtbegin.c,v 1.6 2013/11/29 23:00:48 joerg Exp $);
+__RCSID($NetBSD: crtbegin.c,v 1.7 2013/12/11 06:55:24 matt Exp $);
 
 #include crtbegin.h
 
@@ -39,7 +39,7 @@ __weakref_visible void Jv_RegisterClasse
 	__weak_reference(_Jv_RegisterClasses);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-__dso_hidden const fptr_t __CTOR_LIST__[] __section(.ctors) = {
+__dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(.ctors) = {
 	(fptr_t) -1,
 };
 __dso_hidden extern const fptr_t __CTOR_LIST_END__[];



CVS commit: src/lib/csu/common

2013-11-29 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Nov 29 23:00:49 UTC 2013

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
Include crtbegin.h first to make it possible to build with the stricter
attribute consistency checks in clang.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.5 src/lib/csu/common/crtbegin.c:1.6
--- src/lib/csu/common/crtbegin.c:1.5	Mon Aug 26 14:20:53 2013
+++ src/lib/csu/common/crtbegin.c	Fri Nov 29 23:00:48 2013
@@ -27,7 +27,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: crtbegin.c,v 1.5 2013/08/26 14:20:53 matt Exp $);
+__RCSID($NetBSD: crtbegin.c,v 1.6 2013/11/29 23:00:48 joerg Exp $);
+
+#include crtbegin.h
 
 typedef void (*fptr_t)(void);
 
@@ -131,5 +133,3 @@ __do_global_dtors_aux(void)
 #endif
 }
 #endif /* !__ARM_EABI__ || SHARED */
-
-#include crtbegin.h



CVS commit: src/lib/csu/common

2013-11-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Nov 17 11:16:09 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Simplify previous by using CSU_MACHINE_ARCH. Hint from Takeshi Nakayama.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.22 src/lib/csu/common/Makefile.inc:1.23
--- src/lib/csu/common/Makefile.inc:1.22	Sat Nov 16 10:50:43 2013
+++ src/lib/csu/common/Makefile.inc	Sun Nov 17 11:16:09 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.22 2013/11/16 10:50:43 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.23 2013/11/17 11:16:09 martin Exp $
 
 .include bsd.own.mk
 
@@ -21,7 +21,7 @@ CFLAGS.crtbegin.c+= -fPIE
 OBJS+=		crtfm.o
 .endif
 
-.if ${MACHINE_ARCH} == sparc64  ${COPTS:M-m32} == 
+.if ${CSU_MACHINE_ARCH} == sparc64
 # create helper objects for the compiler to mark compiler memory models
 .for m in medlow medmid medany
 sparc_mc${m}.o:	compident.S sysident_assym.h



CVS commit: src/lib/csu/common

2013-11-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Nov 16 10:50:43 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
We do not want to build the code model markes when creating the 32bit
compat libs for sparc64


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.21 src/lib/csu/common/Makefile.inc:1.22
--- src/lib/csu/common/Makefile.inc:1.21	Thu Nov 14 12:19:34 2013
+++ src/lib/csu/common/Makefile.inc	Sat Nov 16 10:50:43 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.21 2013/11/14 12:19:34 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.22 2013/11/16 10:50:43 martin Exp $
 
 .include bsd.own.mk
 
@@ -21,7 +21,7 @@ CFLAGS.crtbegin.c+= -fPIE
 OBJS+=		crtfm.o
 .endif
 
-.if ${MACHINE_ARCH} == sparc64
+.if ${MACHINE_ARCH} == sparc64  ${COPTS:M-m32} == 
 # create helper objects for the compiler to mark compiler memory models
 .for m in medlow medmid medany
 sparc_mc${m}.o:	compident.S sysident_assym.h



CVS commit: src/lib/csu/common

2013-11-11 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Nov 11 10:24:27 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Explicitly depend on sys/param.h to pick up __NetBSD_Version changes.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.19 src/lib/csu/common/Makefile.inc:1.20
--- src/lib/csu/common/Makefile.inc:1.19	Wed Sep 18 22:53:39 2013
+++ src/lib/csu/common/Makefile.inc	Mon Nov 11 10:24:27 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.19 2013/09/18 22:53:39 uwe Exp $
+#	$NetBSD: Makefile.inc,v 1.20 2013/11/11 10:24:27 joerg Exp $
 
 .include bsd.own.mk
 
@@ -98,7 +98,7 @@ crtfm.o: crtfm.c
 .endif
 
 GENASSYM_CONF=	${COMMON_DIR}/sysident_assym.cf 
-sysident_assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS}
+sysident_assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS} ${NETBSDSRCDIR}/sys/sys/param.h
 	${_MKTARGET_CREATE}
 	cat ${COMMON_DIR}/sysident_assym.cf | \
 	${TOOL_GENASSYM} -- ${CC} ${CFLAGS:N-Wa,*} ${CPPFLAGS} ${PROF} \



CVS commit: src/lib/csu/common

2013-09-18 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Sep 18 22:53:39 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Fix previous: use PICFLAGS for crtbeginS.o
Should unbreak sh3 builds.

XXX: PICFLAGS is defined in bsd.lib.mk which lib/csu does not use.
For now supply a local definition.  joerg@, please fix appropriately.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.18 src/lib/csu/common/Makefile.inc:1.19
--- src/lib/csu/common/Makefile.inc:1.18	Thu Sep 12 15:36:15 2013
+++ src/lib/csu/common/Makefile.inc	Wed Sep 18 22:53:39 2013
@@ -1,7 +1,10 @@
-#	$NetBSD: Makefile.inc,v 1.18 2013/09/12 15:36:15 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.19 2013/09/18 22:53:39 uwe Exp $
 
 .include bsd.own.mk
 
+# XXX: FIXME: This is defined in bsd.lib.mk
+PICFLAGS ?= -fPIC
+
 COMMON_DIR:=	${.CURDIR}/common
 .PATH:		${COMMON_DIR}
 
@@ -38,11 +41,11 @@ crtbegin.o: crtbegin.c crtbegin.h
 .if exists(${ARCHDIR}/crtbegin.S)
 crtbeginS.o: crtbegin.S
 	${_MKTARGET_COMPILE}
-	${COMPILE.S} -DPIC -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+	${COMPILE.S} ${PICFLAGS} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
 .else
 crtbeginS.o: crtbegin.c crtbegin.h
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} -fPIC -DPIC -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
+	${COMPILE.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o



CVS commit: src/lib/csu/common

2013-09-10 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Sep 10 17:23:55 UTC 2013

Modified Files:
src/lib/csu/common: sysident_assym.cf

Log Message:
MARCH note is conditional


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/csu/common/sysident_assym.cf

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/sysident_assym.cf
diff -u src/lib/csu/common/sysident_assym.cf:1.2 src/lib/csu/common/sysident_assym.cf:1.3
--- src/lib/csu/common/sysident_assym.cf:1.2	Tue Sep 10 16:45:33 2013
+++ src/lib/csu/common/sysident_assym.cf	Tue Sep 10 17:23:55 2013
@@ -11,8 +11,10 @@ define	ELF_NOTE_PAX_DESCSZ		ELF_NOTE_PAX
 define	ELF_NOTE_TYPE_PAX_TAG		ELF_NOTE_TYPE_PAX_TAG
 #define	ELF_NOTE_PAX_NAME		ELF_NOTE_PAX_NAME
 
+ifdef ELF_NOTE_MARCH_DESC
 define	ELF_NOTE_MARCH_NAMESZ		ELF_NOTE_MARCH_NAMESZ
 define	ELF_NOTE_MARCH_DESCSZ		sizeof(ELF_NOTE_MARCH_DESC)
 define	ELF_NOTE_TYPE_MARCH_TAG		ELF_NOTE_TYPE_MARCH_TAG
 #define	ELF_NOTE_MARCH_NAME		ELF_NOTE_MARCH_NAME
 #define	ELF_NOTE_MARCH_DESC		ELF_NOTE_MARCH_DESC
+endif



CVS commit: src/lib/csu/common

2013-08-26 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Mon Aug 26 14:20:53 UTC 2013

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
MIPS wants a read/write eh_frame.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.4 src/lib/csu/common/crtbegin.c:1.5
--- src/lib/csu/common/crtbegin.c:1.4	Mon Aug 19 22:15:13 2013
+++ src/lib/csu/common/crtbegin.c	Mon Aug 26 14:20:53 2013
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: crtbegin.c,v 1.4 2013/08/19 22:15:13 matt Exp $);
+__RCSID($NetBSD: crtbegin.c,v 1.5 2013/08/26 14:20:53 matt Exp $);
 
 typedef void (*fptr_t)(void);
 
@@ -53,7 +53,11 @@ __dso_hidden void *__dso_handle;
 #endif
 
 #if !defined(__ARM_EABI__)
-__dso_hidden const long __EH_FRAME_LIST__[0] __section(.eh_frame);
+__dso_hidden
+#if !defined(__mips__)
+	const
+#endif
+	long __EH_FRAME_LIST__[0] __section(.eh_frame);
 
 __weakref_visible void register_frame_info(const void *, const void *)
 	__weak_reference(__register_frame_info);



CVS commit: src/lib/csu/common

2013-08-19 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Mon Aug 19 22:15:13 UTC 2013

Modified Files:
src/lib/csu/common: crtbegin.c

Log Message:
Put the ctors code in .text.startup and dtors code in .text.exit


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.3 src/lib/csu/common/crtbegin.c:1.4
--- src/lib/csu/common/crtbegin.c:1.3	Thu Jun 27 21:24:39 2013
+++ src/lib/csu/common/crtbegin.c	Mon Aug 19 22:15:13 2013
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: crtbegin.c,v 1.3 2013/06/27 21:24:39 matt Exp $);
+__RCSID($NetBSD: crtbegin.c,v 1.4 2013/08/19 22:15:13 matt Exp $);
 
 typedef void (*fptr_t)(void);
 
@@ -65,7 +65,7 @@ static long dwarf_eh_object[8];
 
 static void __do_global_ctors_aux(void) __used;
 
-static void
+static void __section(.text.startup)
 __do_global_ctors_aux(void)
 {
 	static unsigned char __initialized;
@@ -100,7 +100,7 @@ __dso_hidden extern const fptr_t __DTOR_
 
 static void __do_global_dtors_aux(void) __used;
 
-static void
+static void __section(.text.exit)
 __do_global_dtors_aux(void)
 {
 	static unsigned char __finished;



CVS commit: src/lib/csu/common

2013-07-18 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jul 18 18:43:56 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Only supplie -fPIE to crtbegin.c if MKPIC is yes.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.14 src/lib/csu/common/Makefile.inc:1.15
--- src/lib/csu/common/Makefile.inc:1.14	Wed Jul 17 14:23:45 2013
+++ src/lib/csu/common/Makefile.inc	Thu Jul 18 18:43:56 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.14 2013/07/17 14:23:45 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.15 2013/07/18 18:43:56 matt Exp $
 
 .include bsd.own.mk
 
@@ -12,6 +12,7 @@ OBJS+=		crtbegin.o crtend.o
 
 .if ${MKPIC} == yes
 OBJS+=		crtbeginS.o
+CFLAGS.crtbegin.c+= -fPIE
 .endif
 
 realall: ${OBJS}
@@ -23,7 +24,7 @@ crtbegin.o: crtbegin.S
 .else
 crtbegin.o: crtbegin.c crtbegin.h
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} -fPIE ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
+	${COMPILE.c} ${CFLAGS.crtbegin.c} ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o



CVS commit: src/lib/csu/common

2013-07-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Jul  5 02:06:49 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Only install crtbeginS.o, crtbeginT.o and crtendS.o when MKPIC=yes.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.12 src/lib/csu/common/Makefile.inc:1.13
--- src/lib/csu/common/Makefile.inc:1.12	Thu Jun 27 21:24:39 2013
+++ src/lib/csu/common/Makefile.inc	Fri Jul  5 02:06:49 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.12 2013/06/27 21:24:39 matt Exp $
+#	$NetBSD: Makefile.inc,v 1.13 2013/07/05 02:06:49 joerg Exp $
 
 .include bsd.own.mk
 
@@ -8,7 +8,11 @@ COMMON_DIR:=	${.CURDIR}/common
 CPPFLAGS+=	-I${NETBSDSRCDIR}/libexec/ld.elf_so -I${COMMON_DIR} -I.
 
 OBJS+=		crt0.o gcrt0.o crti.o crtn.o
-OBJS+=		crtbegin.o crtbeginS.o crtend.o
+OBJS+=		crtbegin.o crtend.o
+
+.if ${MKPIC} == yes
+OBJS+=		crtbeginS.o
+.endif
 
 realall: ${OBJS}
 
@@ -92,7 +96,10 @@ crtn.o: crtn.S
 FILES=${OBJS}
 FILESDIR=${LIBDIR}
 CLEANFILES+=${OBJS}
+
+.if ${MKPIC} == yes
 SYMLINKS+=	crtbegin.o ${LIBDIR}/crtbeginT.o
 SYMLINKS+=	crtend.o ${LIBDIR}/crtendS.o
+.endif
 
 .include bsd.prog.mk



CVS commit: src/lib/csu/common

2013-06-26 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 27 03:37:21 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Add -fPIC to compile of crtbeginS.o


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.10 src/lib/csu/common/Makefile.inc:1.11
--- src/lib/csu/common/Makefile.inc:1.10	Tue Jun 25 07:18:02 2013
+++ src/lib/csu/common/Makefile.inc	Thu Jun 27 03:37:21 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.10 2013/06/25 07:18:02 matt Exp $
+#	$NetBSD: Makefile.inc,v 1.11 2013/06/27 03:37:21 matt Exp $
 
 .include bsd.own.mk
 
@@ -34,7 +34,7 @@ crtbeginS.o: crtbegin.S
 .else
 crtbeginS.o: crtbegin.c crtbegin.h
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} -DPIC -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
+	${COMPILE.c} -fPIC -DPIC -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o



CVS commit: src/lib/csu/common

2013-06-25 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Jun 25 07:18:02 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Reorder to avoid !exists
Add a crtbegin.h dependency


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.9 src/lib/csu/common/Makefile.inc:1.10
--- src/lib/csu/common/Makefile.inc:1.9	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/common/Makefile.inc	Tue Jun 25 07:18:02 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.9 2013/06/22 02:37:09 matt Exp $
+#	$NetBSD: Makefile.inc,v 1.10 2013/06/25 07:18:02 matt Exp $
 
 .include bsd.own.mk
 
@@ -12,14 +12,14 @@ OBJS+=		crtbegin.o crtbeginS.o crtend.o
 
 realall: ${OBJS}
 
-.if !exists(${ARCHDIR}/crtbegin.S)
-crtbegin.o: crtbegin.c
-	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
-.else
+.if exists(${ARCHDIR}/crtbegin.S)
 crtbegin.o: crtbegin.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+.else
+crtbegin.o: crtbegin.c crtbegin.h
+	${_MKTARGET_COMPILE}
+	${COMPILE.c} ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
@@ -27,14 +27,14 @@ crtbegin.o: crtbegin.S
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif
 
-.if !exists(${ARCHDIR}/crtbegin.S)
-crtbeginS.o: crtbegin.c
-	${_MKTARGET_COMPILE}
-	${COMPILE.c} -DPIC -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
-.else
+.if exists(${ARCHDIR}/crtbegin.S)
 crtbeginS.o: crtbegin.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} -DPIC -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+.else
+crtbeginS.o: crtbegin.c crtbegin.h
+	${_MKTARGET_COMPILE}
+	${COMPILE.c} -DPIC -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o



CVS commit: src/lib/csu/common

2013-06-21 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sat Jun 22 02:21:58 UTC 2013

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Allow crtbegin to be a C file.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.7 src/lib/csu/common/Makefile.inc:1.8
--- src/lib/csu/common/Makefile.inc:1.7	Sun Mar 25 06:55:19 2012
+++ src/lib/csu/common/Makefile.inc	Sat Jun 22 02:21:58 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.7 2012/03/25 06:55:19 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.8 2013/06/22 02:21:58 matt Exp $
 
 .include bsd.own.mk
 
@@ -12,18 +12,30 @@ OBJS+=		crtbegin.o crtbeginS.o crtend.o
 
 realall: ${OBJS}
 
+.if exists(${ARCHDIR}/crtbegin.c)
+crtbegin.o: crtbegin.c
+	${_MKTARGET_COMPILE}
+	${COMPILE.c} ${ARCHDIR}/crtbegin.c -o ${.TARGET}.o
+.else
 crtbegin.o: crtbegin.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+.endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif
 
+.if exists(${ARCHDIR}/crtbegin.c)
+crtbeginS.o: crtbegin.c
+	${_MKTARGET_COMPILE}
+	${COMPILE.c} -DPIC -DSHARED ${ARCHDIR}/crtbegin.c -o ${.TARGET}.o
+.else
 crtbeginS.o: crtbegin.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.S} -DPIC -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+.endif
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no



CVS commit: src/lib/csu/common

2013-01-31 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jan 31 22:24:25 UTC 2013

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Add support for PREINIT_ARRAY


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.12 src/lib/csu/common/crt0-common.c:1.13
--- src/lib/csu/common/crt0-common.c:1.12	Mon Jan 28 16:56:39 2013
+++ src/lib/csu/common/crt0-common.c	Thu Jan 31 22:24:25 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.12 2013/01/28 16:56:39 matt Exp $ */
+/* $NetBSD: crt0-common.c,v 1.13 2013/01/31 22:24:25 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.12 2013/01/28 16:56:39 matt Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.13 2013/01/31 22:24:25 matt Exp $);
 
 #include sys/types.h
 #include sys/exec.h
@@ -95,6 +95,10 @@ do {		\
  * Since we don't need .init or .fini sections, just code them in C
  * to make life easier.
  */
+__weakref_visible const fptr_t preinit_array_start[1]
+__weak_reference(__preinit_array_start);
+__weakref_visible const fptr_t preinit_array_end[1]
+__weak_reference(__preinit_array_end);
 __weakref_visible const fptr_t init_array_start[1]
 __weak_reference(__init_array_start);
 __weakref_visible const fptr_t init_array_end[1]
@@ -105,6 +109,14 @@ __weakref_visible const fptr_t fini_arra
 __weak_reference(__fini_array_end);
 
 static inline void
+_preinit(void)
+{
+	for (const fptr_t *f = preinit_array_start; f  preinit_array_end; f++) {
+		(*f)();
+	}
+}
+
+static inline void
 _init(void)
 {
 	for (const fptr_t *f = init_array_start; f  init_array_end; f++) {
@@ -156,6 +168,10 @@ ___start(void (*cleanup)(void),			/* fro
 
 	_libc_init();
 
+#ifdef HAVE_INITFINI_ARRAY
+	_preinit();
+#endif
+
 #ifdef MCRT0
 	atexit(_mcleanup);
 	monstartup((u_long)__eprol, (u_long)__etext);



CVS commit: src/lib/csu/common

2013-01-28 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Mon Jan 28 16:56:39 UTC 2013

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Use __weakref_visible (from joerg@)


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.11 src/lib/csu/common/crt0-common.c:1.12
--- src/lib/csu/common/crt0-common.c:1.11	Mon Jan 28 06:17:57 2013
+++ src/lib/csu/common/crt0-common.c	Mon Jan 28 16:56:39 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.11 2013/01/28 06:17:57 matt Exp $ */
+/* $NetBSD: crt0-common.c,v 1.12 2013/01/28 16:56:39 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.11 2013/01/28 06:17:57 matt Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.12 2013/01/28 16:56:39 matt Exp $);
 
 #include sys/types.h
 #include sys/exec.h
@@ -95,17 +95,14 @@ do {		\
  * Since we don't need .init or .fini sections, just code them in C
  * to make life easier.
  */
-#if __GNUC_PREREQ__(4,5) || defined(__clang__)
-static const fptr_t init_array_start[1] __weak_reference(__init_array_start);
-static const fptr_t init_array_end[1] __weak_reference(__init_array_end);
-static const fptr_t fini_array_start[1] __weak_reference(__fini_array_start);
-static const fptr_t fini_array_end[1] __weak_reference(__fini_array_end);
-#else
-extern const fptr_t init_array_start[] __weak_reference(__init_array_start);
-extern const fptr_t init_array_end[] __weak_reference(__init_array_end);
-extern const fptr_t fini_array_start[] __weak_reference(__fini_array_start);
-extern const fptr_t fini_array_end[] __weak_reference(__fini_array_end);
-#endif
+__weakref_visible const fptr_t init_array_start[1]
+__weak_reference(__init_array_start);
+__weakref_visible const fptr_t init_array_end[1]
+__weak_reference(__init_array_end);
+__weakref_visible const fptr_t fini_array_start[1]
+__weak_reference(__fini_array_start);
+__weakref_visible const fptr_t fini_array_end[1]
+__weak_reference(__fini_array_end);
 
 static inline void
 _init(void)



CVS commit: src/lib/csu/common

2013-01-27 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Mon Jan 28 06:17:57 UTC 2013

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Make with work with gcc 4.5 or clang.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.10 src/lib/csu/common/crt0-common.c:1.11
--- src/lib/csu/common/crt0-common.c:1.10	Tue Jan 22 22:57:37 2013
+++ src/lib/csu/common/crt0-common.c	Mon Jan 28 06:17:57 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.10 2013/01/22 22:57:37 matt Exp $ */
+/* $NetBSD: crt0-common.c,v 1.11 2013/01/28 06:17:57 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.10 2013/01/22 22:57:37 matt Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.11 2013/01/28 06:17:57 matt Exp $);
 
 #include sys/types.h
 #include sys/exec.h
@@ -95,10 +95,17 @@ do {		\
  * Since we don't need .init or .fini sections, just code them in C
  * to make life easier.
  */
+#if __GNUC_PREREQ__(4,5) || defined(__clang__)
+static const fptr_t init_array_start[1] __weak_reference(__init_array_start);
+static const fptr_t init_array_end[1] __weak_reference(__init_array_end);
+static const fptr_t fini_array_start[1] __weak_reference(__fini_array_start);
+static const fptr_t fini_array_end[1] __weak_reference(__fini_array_end);
+#else
 extern const fptr_t init_array_start[] __weak_reference(__init_array_start);
 extern const fptr_t init_array_end[] __weak_reference(__init_array_end);
 extern const fptr_t fini_array_start[] __weak_reference(__fini_array_start);
 extern const fptr_t fini_array_end[] __weak_reference(__fini_array_end);
+#endif
 
 static inline void
 _init(void)



CVS commit: src/lib/csu/common

2013-01-22 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Jan 22 22:57:37 UTC 2013

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Fix static weak (to extern weak)


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.9 src/lib/csu/common/crt0-common.c:1.10
--- src/lib/csu/common/crt0-common.c:1.9	Mon Aug 13 02:15:35 2012
+++ src/lib/csu/common/crt0-common.c	Tue Jan 22 22:57:37 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $ */
+/* $NetBSD: crt0-common.c,v 1.10 2013/01/22 22:57:37 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.10 2013/01/22 22:57:37 matt Exp $);
 
 #include sys/types.h
 #include sys/exec.h
@@ -95,10 +95,10 @@ do {		\
  * Since we don't need .init or .fini sections, just code them in C
  * to make life easier.
  */
-static const fptr_t init_array_start[] __weak_reference(__init_array_start);
-static const fptr_t init_array_end[] __weak_reference(__init_array_end);
-static const fptr_t fini_array_start[] __weak_reference(__fini_array_start);
-static const fptr_t fini_array_end[] __weak_reference(__fini_array_end);
+extern const fptr_t init_array_start[] __weak_reference(__init_array_start);
+extern const fptr_t init_array_end[] __weak_reference(__init_array_end);
+extern const fptr_t fini_array_start[] __weak_reference(__fini_array_start);
+extern const fptr_t fini_array_end[] __weak_reference(__fini_array_end);
 
 static inline void
 _init(void)



CVS commit: src/lib/csu/common

2012-08-12 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Mon Aug 13 02:15:36 UTC 2012

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Add support for init_array/fini_array (conditionalized on HAVE_INITFINI_ARRAY).
[This is needed for ARM EABI.]


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.8 src/lib/csu/common/crt0-common.c:1.9
--- src/lib/csu/common/crt0-common.c:1.8	Thu Mar 22 22:59:43 2012
+++ src/lib/csu/common/crt0-common.c	Mon Aug 13 02:15:35 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.8 2012/03/22 22:59:43 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.8 2012/03/22 22:59:43 joerg Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $);
 
 #include sys/types.h
 #include sys/exec.h
@@ -49,8 +49,10 @@ __RCSID($NetBSD: crt0-common.c,v 1.8 20
 
 extern int main(int, char **, char **);
 
+#ifndef HAVE_INITFINI_ARRAY
 extern void	_init(void);
 extern void	_fini(void);
+#endif
 extern void	_libc_init(void);
 
 /*
@@ -85,6 +87,36 @@ do {		\
 	_exit(1);\
 } while (0)
 
+#ifdef HAVE_INITFINI_ARRAY
+/*
+ * If we are using INIT_ARRAY/FINI_ARRAY and we are linked statically,
+ * we have to process these instead of relying on RTLD to do it for us.
+ *
+ * Since we don't need .init or .fini sections, just code them in C
+ * to make life easier.
+ */
+static const fptr_t init_array_start[] __weak_reference(__init_array_start);
+static const fptr_t init_array_end[] __weak_reference(__init_array_end);
+static const fptr_t fini_array_start[] __weak_reference(__fini_array_start);
+static const fptr_t fini_array_end[] __weak_reference(__fini_array_end);
+
+static inline void
+_init(void)
+{
+	for (const fptr_t *f = init_array_start; f  init_array_end; f++) {
+		(*f)();
+	}
+}
+
+static void
+_fini(void)
+{
+	for (const fptr_t *f = fini_array_start; f  fini_array_end; f++) {
+		(*f)();
+	}
+}
+#endif /* HAVE_INITFINI_ARRAY */
+
 void
 ___start(void (*cleanup)(void),			/* from shared loader */
 const Obj_Entry *obj,			/* from shared loader */



CVS commit: src/lib/csu/common

2012-01-31 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Jan 31 19:58:22 UTC 2012

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Use -DPIC to compile crtbeginS.o since that's what machine/asm.h
headers check.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.3 src/lib/csu/common/Makefile.inc:1.4
--- src/lib/csu/common/Makefile.inc:1.3	Mon Jan 31 17:54:20 2011
+++ src/lib/csu/common/Makefile.inc	Tue Jan 31 19:58:22 2012
@@ -1,4 +1,5 @@
-#	$NetBSD: Makefile.inc,v 1.3 2011/01/31 17:54:20 drochner Exp $
+Warning: Permanently added the RSA host key for IP address '149.20.53.70' to the list of known hosts.
+#	$NetBSD: Makefile.inc,v 1.4 2012/01/31 19:58:22 uwe Exp $
 
 .include bsd.own.mk
 
@@ -23,7 +24,7 @@ crtbegin.o: crtbegin.S
 
 crtbeginS.o: crtbegin.S
 	${_MKTARGET_COMPILE}
-	${COMPILE.S} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+	${COMPILE.S} -DPIC -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no



CVS commit: src/lib/csu/common

2012-01-31 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Jan 31 20:08:28 UTC 2012

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Move crt0.S in front of crt0-common.c when building crt0.o and gcrt0.o.
Reading disassembly is easier when the asm crt0.S trampoline is at the
start, not hidden behind the C code in crt0-common.c.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.5 src/lib/csu/common/Makefile.inc:1.6
--- src/lib/csu/common/Makefile.inc:1.5	Tue Jan 31 20:03:50 2012
+++ src/lib/csu/common/Makefile.inc	Tue Jan 31 20:08:28 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.5 2012/01/31 20:03:50 uwe Exp $
+#	$NetBSD: Makefile.inc,v 1.6 2012/01/31 20:08:28 uwe Exp $
 
 .include bsd.own.mk
 
@@ -45,22 +45,22 @@ PICFLAGS=	-fPIC
 PICFLAGS=
 .endif
 
-crt0.o: crt0-common.c crt0.S
+crt0.o: crt0.S crt0-common.c
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
 	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.c.o ${.TARGET}.S.o
-	rm -f ${.TARGET}.c.o ${.TARGET}.S.o
+	${COMPILE.c} ${PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
+	${LD} -x -r -o ${.TARGET} ${.TARGET}.S.o ${.TARGET}.c.o
+	rm -f ${.TARGET}.S.o ${.TARGET}.c.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif
 
-gcrt0.o: crt0-common.c crt0.S
+gcrt0.o: crt0.S crt0-common.c
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${PICFLAGS} -DMCRT0 ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
 	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
-	${LD} -x -r -o ${.TARGET} ${.TARGET}.c.o ${.TARGET}.S.o
-	rm -f ${.TARGET}.c.o ${.TARGET}.S.o
+	${COMPILE.c} ${PICFLAGS} -DMCRT0 ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
+	${LD} -x -r -o ${.TARGET} ${.TARGET}.S.o ${.TARGET}.c.o
+	rm -f ${.TARGET}.S.o ${.TARGET}.c.o
 .if ${MKSTRIPIDENT} != no
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif



CVS commit: src/lib/csu/common

2011-06-30 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 30 20:07:36 UTC 2011

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Mark ___start as .hidden (for MKPIE=yes executables).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.6 src/lib/csu/common/crt0-common.c:1.7
--- src/lib/csu/common/crt0-common.c:1.6	Thu Jun 30 19:48:43 2011
+++ src/lib/csu/common/crt0-common.c	Thu Jun 30 20:07:35 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.6 2011/06/30 19:48:43 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.7 2011/06/30 20:07:35 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.6 2011/06/30 19:48:43 joerg Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.7 2011/06/30 20:07:35 matt Exp $);
 
 #include sys/types.h
 #include sys/exec.h
@@ -74,7 +74,7 @@
 static char	 empty_string[] = ;
 char		*__progname = empty_string;
 
-void		___start(void (*)(void), const Obj_Entry *,
+__dso_hidden void ___start(void (*)(void), const Obj_Entry *,
 			 struct ps_strings *);
 
 #define	write(fd, s, n)	__syscall(SYS_write, (fd), (s), (n))



CVS commit: src/lib/csu/common

2011-02-18 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Feb 18 23:37:36 UTC 2011

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Allow building with the changed weakref semantic in GCC 4.2 and clang.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.2 src/lib/csu/common/crt0-common.c:1.3
--- src/lib/csu/common/crt0-common.c:1.2	Tue Feb  8 02:03:13 2011
+++ src/lib/csu/common/crt0-common.c	Fri Feb 18 23:37:36 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.2 2011/02/08 02:03:13 matt Exp $ */
+/* $NetBSD: crt0-common.c,v 1.3 2011/02/18 23:37:36 joerg Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.2 2011/02/08 02:03:13 matt Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.3 2011/02/18 23:37:36 joerg Exp $);
 
 #include sys/types.h
 #include sys/syscall.h
@@ -57,7 +57,14 @@
  * if we happen to be compiling without -static but with without any
  * shared libs present, things will still work.
  */
+
+#if __GNUC_PREREQ__(4,2)
+static int rtld_DYNAMIC __attribute__((__weakref__, __alias__(_DYNAMIC)));
+#define	DYNAMIC_SYM	rtld_DYNAMIC
+#else
 extern int _DYNAMIC __weak_reference(_DYNAMIC);
+#define	DYNAMIC_SYM	_DYNAMIC
+#endif
 
 #ifdef MCRT0
 extern void	monstartup(u_long, u_long);
@@ -104,7 +111,7 @@
 	if (ps_strings != NULL)
 		__ps_strings = ps_strings;
 
-	if (_DYNAMIC != NULL) {
+	if (DYNAMIC_SYM != NULL) {
 		if (obj == NULL)
 			_FATAL(NULL Obj_Entry pointer in GOT\n);
 		if (obj-magic != RTLD_MAGIC)



CVS commit: src/lib/csu/common

2011-02-07 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Feb  8 02:03:13 UTC 2011

Modified Files:
src/lib/csu/common: crt0-common.c

Log Message:
Distinguish between a corrupt obj pointer and a null obj pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/csu/common/crt0-common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/crt0-common.c
diff -u src/lib/csu/common/crt0-common.c:1.1 src/lib/csu/common/crt0-common.c:1.2
--- src/lib/csu/common/crt0-common.c:1.1	Sat Aug  7 18:01:33 2010
+++ src/lib/csu/common/crt0-common.c	Tue Feb  8 02:03:13 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.2 2011/02/08 02:03:13 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $);
+__RCSID($NetBSD: crt0-common.c,v 1.2 2011/02/08 02:03:13 matt Exp $);
 
 #include sys/types.h
 #include sys/syscall.h
@@ -105,7 +105,9 @@
 		__ps_strings = ps_strings;
 
 	if (_DYNAMIC != NULL) {
-		if ((obj == NULL) || (obj-magic != RTLD_MAGIC))
+		if (obj == NULL)
+			_FATAL(NULL Obj_Entry pointer in GOT\n);
+		if (obj-magic != RTLD_MAGIC)
 			_FATAL(Corrupt Obj_Entry pointer in GOT\n);
 		if (obj-version != RTLD_VERSION)
 			_FATAL(Dynamic linker version mismatch\n);



CVS commit: src/lib/csu/common

2010-12-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Dec  7 19:51:03 UTC 2010

Modified Files:
src/lib/csu/common: Makefile.inc

Log Message:
Build assembler sources with assembler compile rules.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/csu/common/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.1 src/lib/csu/common/Makefile.inc:1.2
--- src/lib/csu/common/Makefile.inc:1.1	Sat Aug  7 18:01:33 2010
+++ src/lib/csu/common/Makefile.inc	Tue Dec  7 19:51:02 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:33 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.2 2010/12/07 19:51:02 joerg Exp $
 
 .include bsd.own.mk
 
@@ -14,7 +14,7 @@
 
 crtbegin.o: crtbegin.S
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+	${COMPILE.S} ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
@@ -23,7 +23,7 @@
 
 crtbeginS.o: crtbegin.S
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
+	${COMPILE.S} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
@@ -32,7 +32,7 @@
 
 crtend.o: crtend.S
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${ARCHDIR}/crtend.S -o ${.TARGET}.o
+	${COMPILE.S} ${ARCHDIR}/crtend.S -o ${.TARGET}.o
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	rm -f ${.TARGET}.o
 .if ${MKSTRIPIDENT} != no
@@ -48,7 +48,7 @@
 crt0.o: crt0-common.c crt0.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.c} ${PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
-	${COMPILE.c} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
+	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.c.o ${.TARGET}.S.o
 	rm -f ${.TARGET}.c.o ${.TARGET}.S.o
 .if ${MKSTRIPIDENT} != no
@@ -58,7 +58,7 @@
 gcrt0.o: crt0-common.c crt0.S
 	${_MKTARGET_COMPILE}
 	${COMPILE.c} ${PICFLAGS} -DMCRT0 ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
-	${COMPILE.c} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
+	${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
 	${LD} -x -r -o ${.TARGET} ${.TARGET}.c.o ${.TARGET}.S.o
 	rm -f ${.TARGET}.c.o ${.TARGET}.S.o
 .if ${MKSTRIPIDENT} != no