]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Arch-abstraction:
authorNicholas Nethercote <n.nethercote@gmail.com>
Sat, 9 Oct 2004 19:08:08 +0000 (19:08 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sat, 9 Oct 2004 19:08:08 +0000 (19:08 +0000)
- abstract out three ELF constants

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2741

coregrind/ume.c
coregrind/vg_signals.c
coregrind/vg_symtab2.c
coregrind/x86/core_arch.h

index d874065273597a1020063b6f1607d600e93156eb..be5185d4a9580e8115fa55fa5bfea673472d35b9 100644 (file)
@@ -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;
    }
 
index b1a4ac1a57e45985012456982ddce80e650e51f2..9bd8406fee4b2a24bd6551fa7f2aeced66bc0991 100644 (file)
@@ -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);
index 20a9d510a8b8d18537f7225ddc79eb5c7e9eff26..34daa6961e16e7f9fdc438f5a3c78890a300e443 100644 (file)
@@ -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);
index ed3cf7baebd9603b4a1e9891688cd3919c399993..019279808d00795f9635bdbd6bf05ec552416d5b 100644 (file)
@@ -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
    ------------------------------------------------------------------ */