This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH,HURD] Recognize GNU/Hurd-specific binaries
- From: Samuel Thibault <samuel dot thibault at ens-lyon dot org>
- To: roland at redhat dot com
- Cc: libc-alpha at sources dot redhat dot com, jk at jk dot fr dot eu dot org
- Date: Sun, 19 Jun 2011 15:07:24 +0200
- Subject: [PATCH,HURD] Recognize GNU/Hurd-specific binaries
Hello,
Ground issue is this:
http://sourceware.org/bugzilla/show_bug.cgi?id=10549
gcc/glibc now uses GNU-specific extensions to the ELF format (GNU_IFUNC,
GNU_UNIQUE). For such cases, binutils now emits binaries with the
GNU/Linux-specific ELFOSABI_LINUX on GNU/Linux, and should also emit
binaries with the GNU/Hurd-specific ELFOSABI_HURD on GNU/Hurd. The
dynamic linker should thus recognize ELFOSABI_HURD as valid on GNU/Hurd,
as the patch below does. Note that the ELFOSABI_HURD value (4) was
already decided in binutils.
Samuel
2011-06-19 Samuel Thibault <samuel.thibault@ens-lyon.org>
* elf/elf.h (ELFOSABI_HURD): Define macro.
* sysdeps/mach/hurd/ldsodefs.h: New file, defines VALID_ELF_HEADER,
VALID_ELF_OSABI, VALID_ELF_ABIVERSION, MORE_ELF_HEADER_DATA, declares
_dl_non_dynamic_init.
* sysdeps/mach/hurd/powerpc/init-first.c (_dl_non_dynamic_init): Remove
declaration.
* sysdeps/mach/hurd/i386/init-first.c (_dl_non_dynamic_init): Likewise.
diff --git a/elf/elf.h b/elf/elf.h
index acb7762..4ef9bb6 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -143,6 +143,7 @@ typedef struct
#define ELFOSABI_HPUX 1 /* HP-UX */
#define ELFOSABI_NETBSD 2 /* NetBSD. */
#define ELFOSABI_LINUX 3 /* Linux. */
+#define ELFOSABI_HURD 4 /* GNU/Hurd. */
#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
#define ELFOSABI_AIX 7 /* IBM AIX. */
#define ELFOSABI_IRIX 8 /* SGI Irix. */
diff --git a/sysdeps/mach/hurd/ldsodefs.h b/sysdeps/mach/hurd/ldsodefs.h
index e69de29..56e4b03 100644
--- a/sysdeps/mach/hurd/ldsodefs.h
+++ b/sysdeps/mach/hurd/ldsodefs.h
@@ -0,0 +1,52 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+ Copyright (C) 2001, 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LDSODEFS_H
+
+#include <libc-abis.h>
+
+/* Get the real definitions. */
+#include_next <ldsodefs.h>
+
+/* Now define our stuff. */
+
+/* Initialization which is normally done by the dynamic linker. */
+extern void _dl_non_dynamic_init (void) internal_function;
+
+/* Accept binaries which identify the binary as using Linux extensions. */
+#define VALID_ELF_HEADER(hdr,exp,size) (memcmp (hdr, exp, size) == 0 \
+ || memcmp (hdr, expected2, size) == 0)
+#define VALID_ELF_OSABI(osabi) (osabi == ELFOSABI_SYSV \
+ || osabi == ELFOSABI_HURD)
+#define VALID_ELF_ABIVERSION(osabi,ver) \
+ (ver == 0 || (osabi == ELFOSABI_HURD && ver < LIBC_ABI_MAX))
+#define MORE_ELF_HEADER_DATA \
+ static const unsigned char expected2[EI_PAD] = \
+ { \
+ [EI_MAG0] = ELFMAG0, \
+ [EI_MAG1] = ELFMAG1, \
+ [EI_MAG2] = ELFMAG2, \
+ [EI_MAG3] = ELFMAG3, \
+ [EI_CLASS] = ELFW(CLASS), \
+ [EI_DATA] = byteorder, \
+ [EI_VERSION] = EV_CURRENT, \
+ [EI_OSABI] = ELFOSABI_HURD \
+ }
+
+#endif /* ldsodefs.h */
diff --git a/sysdeps/mach/hurd/powerpc/init-first.c b/sysdeps/mach/hurd/powerpc/init-first.c
index 21b5054..2047cac 100644
--- a/sysdeps/mach/hurd/powerpc/init-first.c
+++ b/sysdeps/mach/hurd/powerpc/init-first.c
@@ -32,9 +32,6 @@ extern void __init_misc (int, char **, char **);
#ifdef USE_NONOPTION_FLAGS
extern void __getopt_clean_environment (char **);
#endif
-#ifndef SHARED
-extern void _dl_non_dynamic_init (void) internal_function;
-#endif
extern void __libc_global_ctors (void);
unsigned int __hurd_threadvar_max;
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index e79af1d..7c86609 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -37,9 +37,6 @@ extern void __init_misc (int, char **, char **);
#ifdef USE_NONOPTION_FLAGS
extern void __getopt_clean_environment (char **);
#endif
-#ifndef SHARED
-extern void _dl_non_dynamic_init (void) internal_function;
-#endif
extern void __libc_global_ctors (void);
unsigned int __hurd_threadvar_max;