From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 6BFFF3858C2C for ; Sat, 13 Aug 2022 06:41:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6BFFF3858C2C Received: by mail-pf1-x42e.google.com with SMTP id 130so2426963pfy.6 for ; Fri, 12 Aug 2022 23:41:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc; bh=Y/La/MUbaRLoSTBrRERGILmmq1kS5/abBigy6TFcPLQ=; b=vVPwowFK5ls33DKSH3cHRtDkmWVJ9oJb0nUBZfnBndZcTQZuyQ2Bdz0xWj7JKhd/ap F09EvniPZZ2/nw4mbg6VSSamlQPFbKqicN8oXgowOJGoBdhigEocLgUsuLI2USVXIACb i5z8kBm4O9ZaT525/OBVzoBZtOkz3UkSP3BmD78O36VLoBbtXVijteFtT9IP+mW+IX6l DAR6PL1KncfoBBtL6Jf3hR7cpnuNWKUayUNxoxyBg4n++5zRy5tqX+QyYVxS4pTu/78H 76MnUHqVlzA9qAgUtnc1ZguHv4fVLGc8vWuERKd3UoGwNhwi553HGHw4uKa2PamfYbRb 7zSg== X-Gm-Message-State: ACgBeo1cfvzsUQiEf5dOe55DYgVi2Gmj96oV1FjvSpJHxUu0rPVd93Tf uDzWB2BNTOILxGj5pWXHWIQ5+Q8YvBA= X-Google-Smtp-Source: AA6agR5QWv8kUSoPl38JqYMFQEPMdtKfICy30lWogz3Xp9t3b/GPy5NukYYIEY7hH+UXZ4fuGAWCfQ== X-Received: by 2002:a63:2cd2:0:b0:41c:5901:67d8 with SMTP id s201-20020a632cd2000000b0041c590167d8mr5752398pgs.365.1660372904931; Fri, 12 Aug 2022 23:41:44 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:3fe:1fa:8806:9313]) by smtp.gmail.com with ESMTPSA id a4-20020a1709027e4400b0016bedcced2fsm2885524pln.35.2022.08.12.23.41.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Aug 2022 23:41:44 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 84C341142E96; Sat, 13 Aug 2022 16:11:41 +0930 (ACST) Date: Sat, 13 Aug 2022 16:11:41 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Replace elf_vma with uint64_t Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Aug 2022 06:41:50 -0000 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 --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) -- Alan Modra Australia Development Lab, IBM