From: Nicholas Nethercote Date: Sat, 9 Oct 2004 19:08:08 +0000 (+0000) Subject: Arch-abstraction: X-Git-Tag: svn/VALGRIND_3_0_0~1549 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b24f2570057ef70e5521ce84e2b5651aef439a4d;p=thirdparty%2Fvalgrind.git Arch-abstraction: - abstract out three ELF constants git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2741 --- diff --git a/coregrind/ume.c b/coregrind/ume.c index d874065273..be5185d4a9 100644 --- a/coregrind/ume.c +++ b/coregrind/ume.c @@ -277,12 +277,13 @@ struct elfinfo *readelf(int fd, const char *filename) fprintf(stderr, "valgrind: %s: bad ELF magic\n", filename); return NULL; } - if (e->e.e_ident[EI_CLASS] != ELFCLASS32) { - fprintf(stderr, "valgrind: Can only handle 32-bit executables\n"); + if (e->e.e_ident[EI_CLASS] != VG_ELF_CLASS) { + fprintf(stderr, "valgrind: wrong executable class (eg. 32-bit instead\n" + "valgrind: of 64-bit)\n"); return NULL; } - if (e->e.e_ident[EI_DATA] != ELFDATA2LSB) { - fprintf(stderr, "valgrind: Expecting little-endian\n"); + if (e->e.e_ident[EI_DATA] != VG_ELF_ENDIANNESS) { + fprintf(stderr, "valgrind: wrong endian-ness\n"); return NULL; } if (!(e->e.e_type == ET_EXEC || e->e.e_type == ET_DYN)) { @@ -290,8 +291,8 @@ struct elfinfo *readelf(int fd, const char *filename) return NULL; } - if (e->e.e_machine != EM_386) { - fprintf(stderr, "valgrind: need x86\n"); + if (e->e.e_machine != VG_ELF_MACHINE) { + fprintf(stderr, "valgrind: wrong architecture\n"); return NULL; } diff --git a/coregrind/vg_signals.c b/coregrind/vg_signals.c index b1a4ac1a57..9bd8406fee 100644 --- a/coregrind/vg_signals.c +++ b/coregrind/vg_signals.c @@ -1014,12 +1014,12 @@ static void fill_ehdr(Elf32_Ehdr *ehdr, Int num_phdrs) VG_(memset)(ehdr, 0, sizeof(ehdr)); VG_(memcpy)(ehdr->e_ident, ELFMAG, SELFMAG); - ehdr->e_ident[EI_CLASS] = ELFCLASS32; - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; + ehdr->e_ident[EI_CLASS] = VG_ELF_CLASS; + ehdr->e_ident[EI_DATA] = VG_ELF_ENDIANNESS; ehdr->e_ident[EI_VERSION] = EV_CURRENT; ehdr->e_type = ET_CORE; - ehdr->e_machine = EM_386; + ehdr->e_machine = VG_ELF_MACHINE; ehdr->e_version = EV_CURRENT; ehdr->e_entry = 0; ehdr->e_phoff = sizeof(Elf32_Ehdr); diff --git a/coregrind/vg_symtab2.c b/coregrind/vg_symtab2.c index 20a9d510a8..34daa6961e 100644 --- a/coregrind/vg_symtab2.c +++ b/coregrind/vg_symtab2.c @@ -758,11 +758,11 @@ Bool VG_(is_object_file)(const void *buf) && ehdr->e_ident[EI_MAG1] == 'E' && ehdr->e_ident[EI_MAG2] == 'L' && ehdr->e_ident[EI_MAG3] == 'F'); - ok &= (ehdr->e_ident[EI_CLASS] == ELFCLASS32 - && ehdr->e_ident[EI_DATA] == ELFDATA2LSB + ok &= (ehdr->e_ident[EI_CLASS] == VG_ELF_CLASS + && ehdr->e_ident[EI_DATA] == VG_ELF_ENDIANNESS && ehdr->e_ident[EI_VERSION] == EV_CURRENT); ok &= (ehdr->e_type == ET_EXEC || ehdr->e_type == ET_DYN); - ok &= (ehdr->e_machine == EM_386); + ok &= (ehdr->e_machine == VG_ELF_MACHINE); ok &= (ehdr->e_version == EV_CURRENT); ok &= (ehdr->e_shstrndx != SHN_UNDEF); ok &= (ehdr->e_shoff != 0 && ehdr->e_shnum != 0); diff --git a/coregrind/x86/core_arch.h b/coregrind/x86/core_arch.h index ed3cf7baeb..019279808d 100644 --- a/coregrind/x86/core_arch.h +++ b/coregrind/x86/core_arch.h @@ -128,6 +128,15 @@ extern Int VGOFF_(tls_ptr); extern Int VGOFF_(helper_undefined_instruction); +/* --------------------------------------------------------------------- + Elf stuff + ------------------------------------------------------------------ */ + +#define VG_ELF_ENDIANNESS ELFDATA2LSB +#define VG_ELF_MACHINE EM_386 +#define VG_ELF_CLASS ELFCLASS32 + + /* --------------------------------------------------------------------- Exports of vg_helpers.S ------------------------------------------------------------------ */