[nasm:master] output/elf: remove efmt->rela_size

nasm-bot for H. Peter Anvin hpa at zytor.com
Mon Nov 7 17:12:35 PST 2022


Commit-ID:  7351302477eb66be8a27dc3a5e72a4a1217c6e30
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=7351302477eb66be8a27dc3a5e72a4a1217c6e30
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 7 Nov 2022 09:54:33 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 7 Nov 2022 09:54:33 -0800

output/elf: remove efmt->rela_size

There are no use cases for of RELA on i386, and the intent has always been
that efmt->rel_size would be the size of the desired relocation
section type. Rename it from rel_size to relsize to make it more
obvious that it matches efmt->reltype rather than SHT_REL, and delete
efmt->rela_size to keep it from being misused again.

This should avoid a repeat of:

    https://bugzilla.nasm.us/show_bug.cgi?id=3392807

fixed in adf7507e29f95b4e708275e0c1cb81aea3b12a6b.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 output/outelf.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/output/outelf.c b/output/outelf.c
index d789e1ef..84b21136 100644
--- a/output/outelf.c
+++ b/output/outelf.c
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2019 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2022 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -210,8 +210,7 @@ struct elf_format_info {
     size_t ehdr_size;           /* Size of the ELF header */
     size_t shdr_size;           /* Size of a section header */
     size_t sym_size;            /* Size of a symbol */
-    size_t rel_size;            /* Size of a reltype relocation */
-    size_t rela_size;           /* Size of a RELA relocation */
+    size_t relsize;             /* Size of a reltype relocation */
     char relpfx[8];             /* Relocation section prefix */
     uint32_t reltype;           /* Relocation section type */
     uint16_t e_machine;         /* Header e_machine field */
@@ -484,7 +483,6 @@ static void elf32_init(void)
         sizeof(Elf32_Shdr),
         sizeof(Elf32_Sym),
         sizeof(Elf32_Rel),
-        sizeof(Elf32_Rela),
         ".rel",
         SHT_REL,
         EM_386,
@@ -506,7 +504,6 @@ static void elfx32_init(void)
         sizeof(Elf32_Shdr),
         sizeof(Elf32_Sym),
         sizeof(Elf32_Rela),
-        sizeof(Elf32_Rela),
         ".rela",
         SHT_RELA,
         EM_X86_64,
@@ -528,7 +525,6 @@ static void elf64_init(void)
         sizeof(Elf64_Shdr),
         sizeof(Elf64_Sym),
         sizeof(Elf64_Rela),
-        sizeof(Elf64_Rela),
         ".rela",
         SHT_RELA,
         EM_X86_64,
@@ -1987,27 +1983,24 @@ static void elf_write(void)
             elf_section_header(p - shstrtab, efmt->reltype, 0,
                                stabrelbuf, false, stabrellen,
                                sec_symtab, sec_stab,
-                               efmt->word, efmt->rel_size);
+                               efmt->word, efmt->relsize);
             p += strlen(p) + 1;
         }
     } else if (dfmt_is_dwarf()) {
         /* for dwarf debugging information, create the ten dwarf sections */
 
         /* this function call creates the dwarf sections in memory */
-	int reltype = efmt->reltype;
-	int relsize = (efmt->reltype == SHT_RELA
-		       ? efmt->rela_size : efmt->rel_size);
-        if (dwarf_fsect)
+	if (dwarf_fsect)
             dwarf_generate();
 
         elf_section_header(p - shstrtab, SHT_PROGBITS, 0, arangesbuf, false,
                            arangeslen, 0, 0, 1, 0);
         p += strlen(p) + 1;
 
-        elf_section_header(p - shstrtab, reltype, 0, arangesrelbuf, false,
+        elf_section_header(p - shstrtab, efmt->reltype, 0, arangesrelbuf, false,
 			   arangesrellen, sec_symtab,
                            sec_debug_aranges,
-                           efmt->word, relsize);
+                           efmt->word, efmt->relsize);
         p += strlen(p) + 1;
 
         elf_section_header(p - shstrtab, SHT_PROGBITS, 0, pubnamesbuf,
@@ -2018,10 +2011,10 @@ static void elf_write(void)
                            infolen, 0, 0, 1, 0);
         p += strlen(p) + 1;
 
-        elf_section_header(p - shstrtab, reltype, 0, inforelbuf, false,
+        elf_section_header(p - shstrtab, efmt->reltype, 0, inforelbuf, false,
                            inforellen, sec_symtab,
                            sec_debug_info,
-                           efmt->word, relsize);
+                           efmt->word, efmt->relsize);
         p += strlen(p) + 1;
 
         elf_section_header(p - shstrtab, SHT_PROGBITS, 0, abbrevbuf, false,
@@ -2032,10 +2025,10 @@ static void elf_write(void)
                            linelen, 0, 0, 1, 0);
         p += strlen(p) + 1;
 
-        elf_section_header(p - shstrtab, reltype, 0, linerelbuf, false,
+        elf_section_header(p - shstrtab, efmt->reltype, 0, linerelbuf, false,
                            linerellen, sec_symtab,
                            sec_debug_line,
-                           efmt->word, relsize);
+                           efmt->word, efmt->relsize);
         p += strlen(p) + 1;
 
         elf_section_header(p - shstrtab, SHT_PROGBITS, 0, framebuf, false,
@@ -2077,7 +2070,7 @@ static void elf_write(void)
             elf_section_header(p - shstrtab, efmt->reltype, 0,
                                sects[i]->rel, true, sects[i]->rel->datalen,
                                sec_symtab, sects[i]->shndx,
-                               efmt->word, efmt->rel_size);
+                               efmt->word, efmt->relsize);
             p += strlen(p) + 1;
         }
     }


More information about the Nasm-commits mailing list