diff options
Diffstat (limited to 'binutils/elfcomm.c')
-rw-r--r-- | binutils/elfcomm.c | 119 |
1 files changed, 118 insertions, 1 deletions
diff --git a/binutils/elfcomm.c b/binutils/elfcomm.c index 1a1fae98b99..d5b4313880d 100644 --- a/binutils/elfcomm.c +++ b/binutils/elfcomm.c @@ -150,6 +150,57 @@ byte_get_little_endian (unsigned char *field, int size) | (((unsigned long) (field[2])) << 16) | (((unsigned long) (field[3])) << 24); + case 5: + if (sizeof (elf_vma) == 8) + return ((elf_vma) (field[0])) + | (((elf_vma) (field[1])) << 8) + | (((elf_vma) (field[2])) << 16) + | (((elf_vma) (field[3])) << 24) + | (((elf_vma) (field[4])) << 32); + else if (sizeof (elf_vma) == 4) + /* We want to extract data from an 8 byte wide field and + place it into a 4 byte wide field. Since this is a little + endian source we can just use the 4 byte extraction code. */ + return ((unsigned long) (field[0])) + | (((unsigned long) (field[1])) << 8) + | (((unsigned long) (field[2])) << 16) + | (((unsigned long) (field[3])) << 24); + + case 6: + if (sizeof (elf_vma) == 8) + return ((elf_vma) (field[0])) + | (((elf_vma) (field[1])) << 8) + | (((elf_vma) (field[2])) << 16) + | (((elf_vma) (field[3])) << 24) + | (((elf_vma) (field[4])) << 32) + | (((elf_vma) (field[5])) << 40); + else if (sizeof (elf_vma) == 4) + /* We want to extract data from an 8 byte wide field and + place it into a 4 byte wide field. Since this is a little + endian source we can just use the 4 byte extraction code. */ + return ((unsigned long) (field[0])) + | (((unsigned long) (field[1])) << 8) + | (((unsigned long) (field[2])) << 16) + | (((unsigned long) (field[3])) << 24); + + case 7: + if (sizeof (elf_vma) == 8) + return ((elf_vma) (field[0])) + | (((elf_vma) (field[1])) << 8) + | (((elf_vma) (field[2])) << 16) + | (((elf_vma) (field[3])) << 24) + | (((elf_vma) (field[4])) << 32) + | (((elf_vma) (field[5])) << 40) + | (((elf_vma) (field[6])) << 48); + else if (sizeof (elf_vma) == 4) + /* We want to extract data from an 8 byte wide field and + place it into a 4 byte wide field. Since this is a little + endian source we can just use the 4 byte extraction code. */ + return ((unsigned long) (field[0])) + | (((unsigned long) (field[1])) << 8) + | (((unsigned long) (field[2])) << 16) + | (((unsigned long) (field[3])) << 24); + case 8: if (sizeof (elf_vma) == 8) return ((elf_vma) (field[0])) @@ -197,6 +248,63 @@ byte_get_big_endian (unsigned char *field, int size) | (((unsigned long) (field[1])) << 16) | (((unsigned long) (field[0])) << 24); + case 5: + if (sizeof (elf_vma) == 8) + return ((elf_vma) (field[4])) + | (((elf_vma) (field[3])) << 8) + | (((elf_vma) (field[2])) << 16) + | (((elf_vma) (field[1])) << 24) + | (((elf_vma) (field[0])) << 32); + else if (sizeof (elf_vma) == 4) + { + /* Although we are extracting data from an 8 byte wide field, + we are returning only 4 bytes of data. */ + field += 1; + return ((unsigned long) (field[3])) + | (((unsigned long) (field[2])) << 8) + | (((unsigned long) (field[1])) << 16) + | (((unsigned long) (field[0])) << 24); + } + + case 6: + if (sizeof (elf_vma) == 8) + return ((elf_vma) (field[5])) + | (((elf_vma) (field[4])) << 8) + | (((elf_vma) (field[3])) << 16) + | (((elf_vma) (field[2])) << 24) + | (((elf_vma) (field[1])) << 32) + | (((elf_vma) (field[0])) << 40); + else if (sizeof (elf_vma) == 4) + { + /* Although we are extracting data from an 8 byte wide field, + we are returning only 4 bytes of data. */ + field += 2; + return ((unsigned long) (field[3])) + | (((unsigned long) (field[2])) << 8) + | (((unsigned long) (field[1])) << 16) + | (((unsigned long) (field[0])) << 24); + } + + case 7: + if (sizeof (elf_vma) == 8) + return ((elf_vma) (field[6])) + | (((elf_vma) (field[5])) << 8) + | (((elf_vma) (field[4])) << 16) + | (((elf_vma) (field[3])) << 24) + | (((elf_vma) (field[2])) << 32) + | (((elf_vma) (field[1])) << 40) + | (((elf_vma) (field[0])) << 48); + else if (sizeof (elf_vma) == 4) + { + /* Although we are extracting data from an 8 byte wide field, + we are returning only 4 bytes of data. */ + field += 3; + return ((unsigned long) (field[3])) + | (((unsigned long) (field[2])) << 8) + | (((unsigned long) (field[1])) << 16) + | (((unsigned long) (field[0])) << 24); + } + case 8: if (sizeof (elf_vma) == 8) return ((elf_vma) (field[7])) @@ -209,7 +317,7 @@ byte_get_big_endian (unsigned char *field, int size) | (((elf_vma) (field[0])) << 56); else if (sizeof (elf_vma) == 4) { - /* Although we are extracing data from an 8 byte wide field, + /* Although we are extracting data from an 8 byte wide field, we are returning only 4 bytes of data. */ field += 4; return ((unsigned long) (field[3])) @@ -235,9 +343,18 @@ byte_get_signed (unsigned char *field, int size) return (x ^ 0x80) - 0x80; case 2: return (x ^ 0x8000) - 0x8000; + case 3: + return (x ^ 0x800000) - 0x800000; case 4: return (x ^ 0x80000000) - 0x80000000; + case 5: + case 6: + case 7: case 8: + /* Reads of 5-, 6-, and 7-byte numbers are the result of + trying to read past the end of a buffer, and will therefore + not have meaningful values, so we don't try to deal with + the sign in these cases. */ return x; default: abort (); |