public inbox for binutils-cvs@sourceware.org help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org> To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Replace elf_vma with uint64_t Date: Sat, 13 Aug 2022 06:52:24 +0000 (GMT) [thread overview] Message-ID: <20220813065224.9152F385800A@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=928c411de46e876edd545c3bc0d8bd6a663d0c8f commit 928c411de46e876edd545c3bc0d8bd6a663d0c8f Author: Alan Modra <amodra@gmail.com> Date: Fri Aug 12 17:14:37 2022 +0930 Replace elf_vma with uint64_t This patch replaces all uses of elf_vma with uint64_t, removes tests of sizeof (elf_vma), and does a little tidying of byte_get_little_endian and byte_get_big_endian. Diff: --- binutils/elfcomm.c | 179 ++++++++++++++++++++++++----------------------------- binutils/elfcomm.h | 20 +++--- binutils/readelf.c | 4 +- 3 files changed, 93 insertions(+), 110 deletions(-) diff --git a/binutils/elfcomm.c b/binutils/elfcomm.c index b772176496b..0e7d0b57ac6 100644 --- a/binutils/elfcomm.c +++ b/binutils/elfcomm.c @@ -63,12 +63,12 @@ warn (const char *message, ...) va_end (args); } -void (*byte_put) (unsigned char *, elf_vma, unsigned int); +void (*byte_put) (unsigned char *, uint64_t, unsigned int); void -byte_put_little_endian (unsigned char * field, elf_vma value, unsigned int size) +byte_put_little_endian (unsigned char *field, uint64_t value, unsigned int size) { - if (size > sizeof (elf_vma)) + if (size > sizeof (uint64_t)) { error (_("Unhandled data length: %d\n"), size); abort (); @@ -81,9 +81,9 @@ byte_put_little_endian (unsigned char * field, elf_vma value, unsigned int size) } void -byte_put_big_endian (unsigned char * field, elf_vma value, unsigned int size) +byte_put_big_endian (unsigned char *field, uint64_t value, unsigned int size) { - if (size > sizeof (elf_vma)) + if (size > sizeof (uint64_t)) { error (_("Unhandled data length: %d\n"), size); abort (); @@ -95,9 +95,9 @@ byte_put_big_endian (unsigned char * field, elf_vma value, unsigned int size) } } -elf_vma (*byte_get) (const unsigned char *, unsigned int); +uint64_t (*byte_get) (const unsigned char *, unsigned int); -elf_vma +uint64_t byte_get_little_endian (const unsigned char *field, unsigned int size) { switch (size) @@ -106,61 +106,53 @@ byte_get_little_endian (const unsigned char *field, unsigned int size) return *field; case 2: - return ((unsigned int) (field[0])) - | (((unsigned int) (field[1])) << 8); + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8)); case 3: - return ((unsigned long) (field[0])) - | (((unsigned long) (field[1])) << 8) - | (((unsigned long) (field[2])) << 16); + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[2] << 16)); case 4: - return ((unsigned long) (field[0])) - | (((unsigned long) (field[1])) << 8) - | (((unsigned long) (field[2])) << 16) - | (((unsigned long) (field[3])) << 24); + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[2] << 16) + | ((uint64_t) 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); - /* Fall through. */ + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[2] << 16) + | ((uint64_t) field[3] << 24) + | ((uint64_t) field[4] << 32)); 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); - /* Fall through. */ + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[2] << 16) + | ((uint64_t) field[3] << 24) + | ((uint64_t) field[4] << 32) + | ((uint64_t) field[5] << 40)); 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); - /* Fall through. */ + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[2] << 16) + | ((uint64_t) field[3] << 24) + | ((uint64_t) field[4] << 32) + | ((uint64_t) field[5] << 40) + | ((uint64_t) field[6] << 48)); case 8: - 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) - | (((elf_vma) (field[7])) << 56); - /* Fall through. */ + return ((uint64_t) field[0] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[2] << 16) + | ((uint64_t) field[3] << 24) + | ((uint64_t) field[4] << 32) + | ((uint64_t) field[5] << 40) + | ((uint64_t) field[6] << 48) + | ((uint64_t) field[7] << 56)); default: error (_("Unhandled data length: %d\n"), size); @@ -168,7 +160,7 @@ byte_get_little_endian (const unsigned char *field, unsigned int size) } } -elf_vma +uint64_t byte_get_big_endian (const unsigned char *field, unsigned int size) { switch (size) @@ -177,60 +169,53 @@ byte_get_big_endian (const unsigned char *field, unsigned int size) return *field; case 2: - return ((unsigned int) (field[1])) | (((int) (field[0])) << 8); + return ((uint64_t) field[1] + | ((uint64_t) field[0] << 8)); case 3: - return ((unsigned long) (field[2])) - | (((unsigned long) (field[1])) << 8) - | (((unsigned long) (field[0])) << 16); + return ((uint64_t) field[2] + | ((uint64_t) field[1] << 8) + | ((uint64_t) field[0] << 16)); case 4: - return ((unsigned long) (field[3])) - | (((unsigned long) (field[2])) << 8) - | (((unsigned long) (field[1])) << 16) - | (((unsigned long) (field[0])) << 24); + return ((uint64_t) field[3] + | ((uint64_t) field[2] << 8) + | ((uint64_t) field[1] << 16) + | ((uint64_t) 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); - /* Fall through. */ + return ((uint64_t) field[4] + | ((uint64_t) field[3] << 8) + | ((uint64_t) field[2] << 16) + | ((uint64_t) field[1] << 24) + | ((uint64_t) field[0] << 32)); 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); - /* Fall through. */ + return ((uint64_t) field[5] + | ((uint64_t) field[4] << 8) + | ((uint64_t) field[3] << 16) + | ((uint64_t) field[2] << 24) + | ((uint64_t) field[1] << 32) + | ((uint64_t) field[0] << 40)); 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); - /* Fall through. */ + return ((uint64_t) field[6] + | ((uint64_t) field[5] << 8) + | ((uint64_t) field[4] << 16) + | ((uint64_t) field[3] << 24) + | ((uint64_t) field[2] << 32) + | ((uint64_t) field[1] << 40) + | ((uint64_t) field[0] << 48)); case 8: - if (sizeof (elf_vma) >= 8) - return ((elf_vma) (field[7])) - | (((elf_vma) (field[6])) << 8) - | (((elf_vma) (field[5])) << 16) - | (((elf_vma) (field[4])) << 24) - | (((elf_vma) (field[3])) << 32) - | (((elf_vma) (field[2])) << 40) - | (((elf_vma) (field[1])) << 48) - | (((elf_vma) (field[0])) << 56); - /* Fall through. */ + return ((uint64_t) field[7] + | ((uint64_t) field[6] << 8) + | ((uint64_t) field[5] << 16) + | ((uint64_t) field[4] << 24) + | ((uint64_t) field[3] << 32) + | ((uint64_t) field[2] << 40) + | ((uint64_t) field[1] << 48) + | ((uint64_t) field[0] << 56)); default: error (_("Unhandled data length: %d\n"), size); @@ -238,10 +223,10 @@ byte_get_big_endian (const unsigned char *field, unsigned int size) } } -elf_vma +uint64_t byte_get_signed (const unsigned char *field, unsigned int size) { - elf_vma x = byte_get (field, size); + uint64_t x = byte_get (field, size); switch (size) { @@ -430,8 +415,8 @@ process_archive_index_and_symbols (struct archive_info *arch, size -= arch->index_num * sizeof_ar_index; /* Convert the index numbers into the host's numeric format. */ - arch->index_array = (elf_vma *) - malloc (arch->index_num * sizeof (* arch->index_array)); + arch->index_array = (uint64_t *) + malloc (arch->index_num * sizeof (*arch->index_array)); if (arch->index_array == NULL) { free (index_buffer); diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h index c2ec8d20904..bab46b03451 100644 --- a/binutils/elfcomm.h +++ b/binutils/elfcomm.h @@ -29,16 +29,14 @@ extern void error (const char *, ...) ATTRIBUTE_PRINTF_1; extern void warn (const char *, ...) ATTRIBUTE_PRINTF_1; -typedef unsigned HOST_WIDEST_INT elf_vma; +extern void (*byte_put) (unsigned char *, uint64_t, unsigned int); +extern void byte_put_little_endian (unsigned char *, uint64_t, unsigned int); +extern void byte_put_big_endian (unsigned char *, uint64_t, unsigned int); -extern void (*byte_put) (unsigned char *, elf_vma, unsigned int); -extern void byte_put_little_endian (unsigned char *, elf_vma, unsigned int); -extern void byte_put_big_endian (unsigned char *, elf_vma, unsigned int); - -extern elf_vma (*byte_get) (const unsigned char *, unsigned int); -extern elf_vma byte_get_signed (const unsigned char *, unsigned int); -extern elf_vma byte_get_little_endian (const unsigned char *, unsigned int); -extern elf_vma byte_get_big_endian (const unsigned char *, unsigned int); +extern uint64_t (*byte_get) (const unsigned char *, unsigned int); +extern uint64_t byte_get_signed (const unsigned char *, unsigned int); +extern uint64_t byte_get_little_endian (const unsigned char *, unsigned int); +extern uint64_t byte_get_big_endian (const unsigned char *, unsigned int); #define BYTE_PUT(field, val) byte_put (field, val, sizeof (field)) #define BYTE_GET(field) byte_get (field, sizeof (field)) @@ -53,8 +51,8 @@ struct archive_info { char * file_name; /* Archive file name. */ FILE * file; /* Open file descriptor. */ - elf_vma index_num; /* Number of symbols in table. */ - elf_vma * index_array; /* The array of member offsets. */ + uint64_t index_num; /* Number of symbols in table. */ + uint64_t * index_array; /* The array of member offsets. */ char * sym_table; /* The symbol table. */ unsigned long sym_size; /* Size of the symbol table. */ char * longnames; /* The long file names table. */ diff --git a/binutils/readelf.c b/binutils/readelf.c index ed764591765..af443aa6a97 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -13395,10 +13395,10 @@ display_lto_symtab (Filedata * filedata, unsigned int kind = *data++; unsigned int visibility = *data++; - elf_vma size = byte_get (data, 8); + uint64_t size = byte_get (data, 8); data += 8; - elf_vma slot = byte_get (data, 4); + uint64_t slot = byte_get (data, 4); data += 4; if (ext_data != NULL)
reply other threads:[~2022-08-13 6:52 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220813065224.9152F385800A@sourceware.org \ --to=amodra@sourceware.org \ --cc=bfd-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).