crunchide(1): fix offset for x86_64, restores WORLD_LDVER
authorJohn Marino <draco@marino.st>
Mon, 16 Feb 2015 19:08:17 +0000 (20:08 +0100)
committerJohn Marino <draco@marino.st>
Mon, 16 Feb 2015 20:11:03 +0000 (21:11 +0100)
The e_shoff offset for x86_64 is 40, not 44.  FreeBSD figured this out
in January.  The gold linker figured out there was a problem with the
crunch binaries when I tried WORLD_LDVER=ld.gold and it broke on initrd.
The ld.bfd linker didn't squawk.  With the FreeBSD patch, buildworld
completes using the gold linker once again.

While here, tidy up a bit.

usr.bin/crunch/crunchide/Makefile
usr.bin/crunch/crunchide/exec_elf32.c
usr.bin/crunch/crunchide/exec_elf64.c

index de57326..66cef35 100644 (file)
@@ -5,9 +5,7 @@ SRCS=   crunchide.c
 
 TARGET_ARCH?=  ${MACHINE_ARCH}
 
-.if ${TARGET_ARCH} == ia64 || ${TARGET_ARCH} == powerpc64 || \
-    ${TARGET_ARCH} == sparc64 || ${TARGET_ARCH} == x86_64 || \
-    ${TARGET_ARCH:Mmips64*}
+.if ${TARGET_ARCH} == x86_64
 CFLAGS+=-DNLIST_ELF64
 SRCS+= exec_elf64.c
 exec_elf64.o: exec_elf32.c
index 35819e1..f63d09e 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <errno.h>
 #include <limits.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -166,6 +167,10 @@ ELFNAMEEND(check)(int fd, const char *fn)
        switch (xe16toh(eh.e_machine)) {
        case EM_386: break;
        case EM_ALPHA: break;
+#ifndef EM_AARCH64
+#define        EM_AARCH64      183
+#endif
+       case EM_AARCH64: break;
 #ifndef EM_ARM
 #define EM_ARM         40
 #endif
@@ -178,10 +183,6 @@ ELFNAMEEND(check)(int fd, const char *fn)
 #endif
        case EM_MIPS: break;
        case /* EM_MIPS_RS3_LE */ EM_MIPS_RS4_BE: break;
-#ifndef EM_IA_64
-#define        EM_IA_64        50
-#endif
-       case EM_IA_64: break;
 #ifndef EM_PPC
 #define        EM_PPC          20
 #endif
@@ -456,7 +457,7 @@ ELFNAMEEND(hide)(int fd, const char *fn)
                        if (layoutp[i].shdr == &shdrshdr &&
                            ehdr.e_shoff != shdrshdr.sh_offset) {
                                ehdr.e_shoff = shdrshdr.sh_offset;
-                               off = (ELFSIZE == 32) ? 32 : 44;
+                               off = offsetof(Elf_Ehdr, e_shoff);
                                size = sizeof(Elf_Off);
                                if ((size_t)xwriteatoff(fd, &ehdr.e_shoff, off, size,
                                    fn) != size)
index 962cc07..179e45d 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-#ifndef lint
-__IDSTRING(elf64rcsid, "$NetBSD: exec_elf64.c,v 1.2 1997/08/02 21:30:19 perry Exp $");
-#endif
 #define        ELFSIZE         64
 
 #include "exec_elf32.c"