From e027b87cff60a627df186bada3a0481ba01bfce0 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Fri, 10 Aug 2012 15:51:03 +0800 Subject: [PATCH] Remove arch-specific coff headers If we use IMAGE_FILE_MACHINE_AMD64 instead of AMD64MAGIC, we can avoid including the arch-specific coff/x86_64 header. Based on a patch from Maxim Kammerer . Signed-off-by: Jeremy Kerr --- Makefile.am | 2 +- coff/i386.h | 74 --------------------------------------------------- coff/x86_64.h | 57 --------------------------------------- image.c | 2 +- image.h | 1 - 5 files changed, 2 insertions(+), 134 deletions(-) delete mode 100644 coff/i386.h delete mode 100644 coff/x86_64.h diff --git a/Makefile.am b/Makefile.am index 6a52cf7..3e2e707 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,7 @@ AM_CFLAGS = -Wall -Wextra --std=gnu99 bin_PROGRAMS = sbsign sbverify sbattach sbvarsign sbsiglist -coff_headers = coff/external.h coff/pe.h coff/i386.h coff/x86_64.h +coff_headers = coff/external.h coff/pe.h common_SOURCES = idc.c idc.h image.c image.h fileio.c fileio.h $(coff_headers) common_LDADD = lib/ccan/libccan.a $(libcrypto_LIBS) diff --git a/coff/i386.h b/coff/i386.h deleted file mode 100644 index 61e723a..0000000 --- a/coff/i386.h +++ /dev/null @@ -1,74 +0,0 @@ -/* coff information for Intel 386/486. - - Copyright 2001, 2009, 2010 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -#define L_LNNO_SIZE 2 -#define INCLUDE_COMDAT_FIELDS_IN_AUXENT -#include "coff/external.h" - -#define COFF_PAGE_SIZE 0x1000 - -/* Bits for f_flags: - F_RELFLG Relocation info stripped from file - F_EXEC File is executable (no unresolved external references) - F_LNNO Line numbers stripped from file - F_LSYMS Local symbols stripped from file - F_AR32WR File has byte ordering of an AR32WR machine (e.g. vax). */ - -#define F_RELFLG (0x0001) -#define F_EXEC (0x0002) -#define F_LNNO (0x0004) -#define F_LSYMS (0x0008) - -#define I386MAGIC 0x14c -#define I386PTXMAGIC 0x154 -#define I386AIXMAGIC 0x175 - -/* This is Lynx's all-platform magic number for executables. */ - -#define LYNXCOFFMAGIC 0415 - -#define I386BADMAG(x) ( ((x).f_magic != I386MAGIC) \ - && (x).f_magic != I386AIXMAGIC \ - && (x).f_magic != I386PTXMAGIC \ - && (x).f_magic != LYNXCOFFMAGIC) - -#define OMAGIC 0404 /* Object files, eg as output. */ -#define ZMAGIC 0413 /* Demand load format, eg normal ld output. */ -#define STMAGIC 0401 /* Target shlib. */ -#define SHMAGIC 0443 /* Host shlib. */ - -/* Define some NT default values. */ -/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */ -#define NT_SECTION_ALIGNMENT 0x1000 -#define NT_FILE_ALIGNMENT 0x200 -#define NT_DEF_RESERVE 0x100000 -#define NT_DEF_COMMIT 0x1000 - -/* Relocation directives. */ - -struct external_reloc -{ - char r_vaddr[4]; - char r_symndx[4]; - char r_type[2]; -}; - -#define RELOC struct external_reloc -#define RELSZ 10 - diff --git a/coff/x86_64.h b/coff/x86_64.h deleted file mode 100644 index fcd44c8..0000000 --- a/coff/x86_64.h +++ /dev/null @@ -1,57 +0,0 @@ -/* COFF information for AMD 64. - Copyright 2006, 2009, 2010 Free Software Foundation, Inc. - - This file is part of BFD, the Binary File Descriptor library. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. - - Written by Kai Tietz, OneVision Software GmbH&CoKg. */ - -#define L_LNNO_SIZE 2 -#define INCLUDE_COMDAT_FIELDS_IN_AUXENT - -#include "coff/external.h" - -#define COFF_PAGE_SIZE 0x1000 - -#define AMD64MAGIC 0x8664 - -#define AMD64BADMAG(x) ((x).f_magic != AMD64MAGIC) -#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b - -#define OMAGIC 0404 /* Object files, eg as output. */ -#define ZMAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC /* Demand load format, eg normal ld output 0x10b. */ -#define STMAGIC 0401 /* Target shlib. */ -#define SHMAGIC 0443 /* Host shlib. */ - -/* Define some NT default values. */ -/* #define NT_IMAGE_BASE 0x400000 moved to internal.h. */ -#define NT_SECTION_ALIGNMENT 0x1000 -#define NT_FILE_ALIGNMENT 0x200 -#define NT_DEF_RESERVE 0x100000 -#define NT_DEF_COMMIT 0x1000 - -/* Relocation directives. */ - -struct external_reloc -{ - char r_vaddr[4]; - char r_symndx[4]; - char r_type[2]; -}; - -#define RELOC struct external_reloc -#define RELSZ 10 diff --git a/image.c b/image.c index 435f8a5..a67621d 100644 --- a/image.c +++ b/image.c @@ -117,7 +117,7 @@ static int image_pecoff_parse(struct image *image) return -1; } - if (pehdr_u16(image->pehdr->f_magic) != AMD64MAGIC) { + if (pehdr_u16(image->pehdr->f_magic) != IMAGE_FILE_MACHINE_AMD64) { fprintf(stderr, "Invalid PE header magic for x86_64\n"); return -1; } diff --git a/image.h b/image.h index 800c5d3..d0ecd4b 100644 --- a/image.h +++ b/image.h @@ -37,7 +37,6 @@ #include #define DO_NOT_DEFINE_LINENO -#include "coff/x86_64.h" #include "coff/external.h" #include "coff/pe.h"