From 0c21f9489ab174b6d0c42d1cbd8010efad80161a Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 27 Nov 2023 12:04:54 -0600 Subject: [PATCH 1/2] 2022-08-31 version 2.54 --- changelog.txt | 3 ++ src/cmdline.cpp | 9 +++-- src/coff.h | 16 ++++---- src/disasm.h | 24 +++++------ src/disasm2.cpp | 76 +++++++++++++++++------------------ src/elf2cof.cpp | 9 ++++- src/elf2elf.cpp | 58 ++++++++++++++------------ src/maindef.h | 4 +- src/proposed_improvements.txt | 15 +++++++ 9 files changed, 123 insertions(+), 91 deletions(-) create mode 100755 src/proposed_improvements.txt diff --git a/changelog.txt b/changelog.txt index 599d162..86c6360 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2022-08-31 version 2.54 +* fix problem with ELF files having same string table for symbols and sections (generated by rustc compiler) + 2022-04-28 version 2.53 * add disassembler support for AVX512-FP16, etc. diff --git a/src/cmdline.cpp b/src/cmdline.cpp index 09b5a2f..18d4fba 100755 --- a/src/cmdline.cpp +++ b/src/cmdline.cpp @@ -1,14 +1,14 @@ /**************************** cmdline.cpp ********************************** * Author: Agner Fog * Date created: 2006-07-25 -* Last modified: 2022-04-28 +* Last modified: 2023-03-29 * Project: objconv * Module: cmdline.cpp * Description: * This module is for interpretation of command line options * Also contains symbol change function * -* Copyright 2006-2022 GNU General Public License http://www.gnu.org/licenses +* Copyright 2006-2023 GNU General Public License http://www.gnu.org/licenses *****************************************************************************/ #include "stdafx.h" @@ -16,8 +16,11 @@ // List of recognized output file type options static SIntTxt TypeOptionNames[] = { {CMDL_OUTPUT_ELF, "elf"}, + {CMDL_OUTPUT_ELF, "ELF"}, {CMDL_OUTPUT_PE, "pe"}, + {CMDL_OUTPUT_PE, "PE"}, {CMDL_OUTPUT_PE, "coff"}, + {CMDL_OUTPUT_PE, "COFF"}, {CMDL_OUTPUT_PE, "cof"}, {CMDL_OUTPUT_PE, "win"}, {CMDL_OUTPUT_OMF, "omf"}, @@ -1186,7 +1189,7 @@ void CCommandLineInterpreter::ReportStatistics() { void CCommandLineInterpreter::Help() { // Print help message printf("\nObject file converter version %.2f for x86 and x86-64 platforms.", OBJCONV_VERSION); - printf("\nCopyright (c) 2022 by Agner Fog. Gnu General Public License."); + printf("\nCopyright (c) 2023 by Agner Fog. Gnu General Public License."); printf("\n\nUsage: objconv options inputfile [outputfile]"); printf("\n\nOptions:"); printf("\n-fXXX[SS] Output file format XXX, word size SS. Supported formats:"); diff --git a/src/coff.h b/src/coff.h index 7717c65..c305fdf 100755 --- a/src/coff.h +++ b/src/coff.h @@ -1,14 +1,14 @@ /**************************** coff.h ************************************* * Author: Agner Fog * Date created: 2006-07-15 -* Last modified: 2008-06-04 +* Last modified: 2022-08-31 * Project: objconv * Module: coff.h * Description: * Header file for definition of structures in MS Windows COFF Intel x86 (PE) * object file format. * -* Copyright 2006-2008 GNU General Public License http://www.gnu.org/licenses +* Copyright 2006-2022 GNU General Public License http://www.gnu.org/licenses * Parts (c) 1995 DJ Delorie GNU General Public License *****************************************************************************/ @@ -355,12 +355,12 @@ union SCOFF_SymTableEntry { // Section definition struct { uint32_t Length; - uint16_t NumberOfRelocations; // Line number in source file - uint16_t NumberOfLineNumbers; - uint32_t CheckSum; // Pointer to line number entry - uint16_t Number; // Symbol table index of next function - uint8_t Selection; // Unused - uint8_t Unused1[3]; + uint16_t NumberOfRelocations; // Number of relocation entries for the section + uint16_t NumberOfLineNumbers; // Number of line-number entries for the section + uint32_t CheckSum; // Checksum for communal data + uint16_t Number; // Index of associated section (for COMDAT selection 5) + uint8_t Selection; // COMDAT selection number + uint8_t Unused1[3]; // Unused } section; }; diff --git a/src/disasm.h b/src/disasm.h index 299394b..3d00def 100755 --- a/src/disasm.h +++ b/src/disasm.h @@ -1,13 +1,13 @@ /**************************** disasm.h ********************************** * Author: Agner Fog * Date created: 2007-02-21 -* Last modified: 2022-04-25 +* Last modified: 2023-03-29 * Project: objconv * Module: disasm.h * Description: * Header file for disassembler * -* Copyright 2007-2022 GNU General Public License http://www.gnu.org/licenses +* Copyright 2007-2023 GNU General Public License http://www.gnu.org/licenses *****************************************************************************/ #ifndef DISASM_H #define DISASM_H @@ -738,27 +738,27 @@ class CDisassembler { int TranslateAbsAddress(int64_t Addr, int32_t &Sect, uint32_t &Offset); // Translate absolute virtual address to section and offset void WriteFileBegin(); // Write begin of file void WriteFileBeginMASM(); // Write MASM-specific file init - void WriteFileBeginYASM(); // Write YASM-specific file init + void WriteFileBeginNASM(); // Write NASM-specific file init void WriteFileBeginGASM(); // Write GAS-specific file init void WriteFileEnd(); // Write end of file void WriteSegmentBegin(); // Write begin of segment void WriteSegmentBeginMASM(); // Write begin of segment, MASM syntax - void WriteSegmentBeginYASM(); // Write begin of segment, YASM syntax + void WriteSegmentBeginNASM(); // Write begin of segment, NASM syntax void WriteSegmentBeginGASM(); // Write begin of segment, GAS syntax void WriteSegmentEnd(); // Write end of segment void WritePublicsAndExternalsMASM(); // Write public and external symbol definitions, MASM syntax - void WritePublicsAndExternalsYASMGASM(); // Write public and external symbol definitions, YASM and GAS syntax + void WritePublicsAndExternalsNASMGASM(); // Write public and external symbol definitions, NASM and GAS syntax void WriteFunctionBegin(); // Write begin of function void WriteFunctionBeginMASM(uint32_t symi, uint32_t scope);// Write begin of function, MASM syntax - void WriteFunctionBeginYASM(uint32_t symi, uint32_t scope);// Write begin of function, YASM syntax + void WriteFunctionBeginNASM(uint32_t symi, uint32_t scope);// Write begin of function, NASM syntax void WriteFunctionBeginGASM(uint32_t symi, uint32_t scope);// Write begin of function, GAS syntax void WriteFunctionEnd(); // Write end of function void WriteFunctionEndMASM(uint32_t symi); // Write end of function, MASM syntax - void WriteFunctionEndYASM(uint32_t symi); // Write end of function, YASM syntax + void WriteFunctionEndNASM(uint32_t symi); // Write end of function, NASM syntax void WriteFunctionEndGASM(uint32_t symi); // Write end of function, GAS syntax void WriteCodeLabel(uint32_t symi); // Write private or public code label void WriteCodeLabelMASM(uint32_t symi, uint32_t scope);// Write private or public code label, MASM syntax - void WriteCodeLabelYASM(uint32_t symi, uint32_t scope);// Write private or public code label, MASM syntax + void WriteCodeLabelNASM(uint32_t symi, uint32_t scope);// Write private or public code label, MASM syntax void WriteCodeLabelGASM(uint32_t symi, uint32_t scope);// Write private or public code label, MASM syntax int WriteFillers(); // Check if code is a series of NOPs or other fillers. If so then write it as such void WriteAlign(uint32_t a); // Write alignment directive @@ -782,17 +782,17 @@ class CDisassembler { void WriteRelocationTarget(uint32_t irel, uint32_t Context, int64_t Addend);// Write cross reference void WriteOperandType(uint32_t type); // Write type override before operand, e.g. "dword ptr" void WriteOperandTypeMASM(uint32_t type); // Write type override before operand, e.g. "dword ptr", MASM syntax - void WriteOperandTypeYASM(uint32_t type); // Write type override before operand, e.g. "dword", YASM syntax + void WriteOperandTypeNASM(uint32_t type); // Write type override before operand, e.g. "dword", NASM syntax void WriteOperandTypeGASM(uint32_t type); // Write type override before operand, e.g. "dword ptr", GAS syntax void WriteDataItems(); // Write data items void WriteDataLabelMASM(const char * name, uint32_t sym, int line); // Write label before data item, MASM syntax - void WriteDataLabelYASM(const char * name, uint32_t sym, int line); // Write label before data item, YASM syntax + void WriteDataLabelNASM(const char * name, uint32_t sym, int line); // Write label before data item, NASM syntax void WriteDataLabelGASM(const char * name, uint32_t sym, int line); // Write label before data item, GAS syntax void WriteUninitDataItemsMASM(uint32_t size, uint32_t count);// Write uninitialized (BSS) data, MASM syntax - void WriteUninitDataItemsYASM(uint32_t size, uint32_t count);// Write uninitialized (BSS) data, YASM syntax + void WriteUninitDataItemsNASM(uint32_t size, uint32_t count);// Write uninitialized (BSS) data, NASM syntax void WriteUninitDataItemsGASM(uint32_t size, uint32_t count);// Write uninitialized (BSS) data, GAS syntax void WriteDataDirectiveMASM(uint32_t size); // Write DB, etc., MASM syntax - void WriteDataDirectiveYASM(uint32_t size); // Write DB, etc., MASM syntax + void WriteDataDirectiveNASM(uint32_t size); // Write DB, etc., MASM syntax void WriteDataDirectiveGASM(uint32_t size); // Write DB, etc., MASM syntax void WriteDataComment(uint32_t ElementSize, uint32_t LinePos, uint32_t Pos, uint32_t irel);// Write comment after data item uint32_t GetDataItemSize(uint32_t Type); // Get size of data item with specified type diff --git a/src/disasm2.cpp b/src/disasm2.cpp index c5abbc9..109f69d 100755 --- a/src/disasm2.cpp +++ b/src/disasm2.cpp @@ -1,7 +1,7 @@ /**************************** disasm2.cpp ******************************** * Author: Agner Fog * Date created: 2007-02-25 -* Last modified: 2022-04-25 +* Last modified: 2023-03-29 * Project: objconv * Module: disasm2.cpp * Description: @@ -9,7 +9,7 @@ * * Changes that relate to assembly language syntax should be done in this file only. * -* Copyright 2007-2022 GNU General Public License http://www.gnu.org/licenses +* Copyright 2007-2023 GNU General Public License http://www.gnu.org/licenses *****************************************************************************/ #include "stdafx.h" @@ -387,7 +387,7 @@ void CDisassembler::WriteOperandType(uint32_t type) { case SUBTYPE_MASM: WriteOperandTypeMASM(type); break; case SUBTYPE_NASM: - WriteOperandTypeYASM(type); break; + WriteOperandTypeNASM(type); break; case SUBTYPE_GASM: WriteOperandTypeGASM(type); break; } @@ -458,7 +458,7 @@ void CDisassembler::WriteOperandTypeMASM(uint32_t type) { if (type) OutFile.Put("ptr "); } -void CDisassembler::WriteOperandTypeYASM(uint32_t type) { +void CDisassembler::WriteOperandTypeNASM(uint32_t type) { // Write type override before operand, e.g. "dword", NASM/YASM syntax if (type & 0xF00) { type &= 0xF00; // Ignore element type for vectors @@ -478,7 +478,7 @@ void CDisassembler::WriteOperandTypeYASM(uint32_t type) { OutFile.Put("far "); } else { - // Size currently not supported by YASM + // Size currently not supported by NASM switch (type) { case 3: OutFile.Put("far "); s.OpComment = "16+16 bit. Needs 66H prefix"; @@ -1461,7 +1461,7 @@ void CDisassembler::WriteDataItems() { case SUBTYPE_MASM: WriteDataLabelMASM(Symname, sym, SeparateLine); break; case SUBTYPE_NASM: - WriteDataLabelYASM(Symname, sym, SeparateLine); break; + WriteDataLabelNASM(Symname, sym, SeparateLine); break; case SUBTYPE_GASM: WriteDataLabelGASM(Symname, sym, SeparateLine); break; } @@ -1483,7 +1483,7 @@ void CDisassembler::WriteDataItems() { case SUBTYPE_MASM: WriteUninitDataItemsMASM(ElementSize, DataCount); break; case SUBTYPE_NASM: - WriteUninitDataItemsYASM(ElementSize, DataCount); break; + WriteUninitDataItemsNASM(ElementSize, DataCount); break; case SUBTYPE_GASM: WriteUninitDataItemsGASM(ElementSize, DataCount); break; } @@ -1504,7 +1504,7 @@ void CDisassembler::WriteDataItems() { case SUBTYPE_MASM: WriteUninitDataItemsMASM(ElementSize, DataCount); break; case SUBTYPE_NASM: - WriteUninitDataItemsYASM(ElementSize, DataCount); break; + WriteUninitDataItemsNASM(ElementSize, DataCount); break; case SUBTYPE_GASM: WriteUninitDataItemsGASM(ElementSize, DataCount); break; } @@ -1609,7 +1609,7 @@ void CDisassembler::WriteDataItems() { case SUBTYPE_MASM: WriteDataDirectiveMASM(ElementSize); break; case SUBTYPE_NASM: - WriteDataDirectiveYASM(ElementSize); break; + WriteDataDirectiveNASM(ElementSize); break; case SUBTYPE_GASM: WriteDataDirectiveGASM(ElementSize); break; } @@ -1746,8 +1746,8 @@ void CDisassembler::WriteDataLabelMASM(const char * name, uint32_t sym, int line } } -void CDisassembler::WriteDataLabelYASM(const char * name, uint32_t sym, int line) { - // Write label before data item, YASM syntax +void CDisassembler::WriteDataLabelNASM(const char * name, uint32_t sym, int line) { + // Write label before data item, NASM syntax // name = name of data item(s) // sym = symbol index // line = 1 if label is on separate line, 0 if data follows on same line @@ -1896,8 +1896,8 @@ void CDisassembler::WriteUninitDataItemsMASM(uint32_t size, uint32_t count) { } } -void CDisassembler::WriteUninitDataItemsYASM(uint32_t size, uint32_t count) { - // Write uninitialized (BSS) data, YASM syntax +void CDisassembler::WriteUninitDataItemsNASM(uint32_t size, uint32_t count) { + // Write uninitialized (BSS) data, NASM syntax // Write data definition directive for appropriate size switch (size) { case 1: @@ -1943,8 +1943,8 @@ void CDisassembler::WriteDataDirectiveMASM(uint32_t size) { } } -void CDisassembler::WriteDataDirectiveYASM(uint32_t size) { - // Write DB, etc., YASM syntax +void CDisassembler::WriteDataDirectiveNASM(uint32_t size) { + // Write DB, etc., NASM syntax // Write data definition directive for appropriate size switch (size) { case 1: OutFile.Put("db "); break; @@ -2541,12 +2541,12 @@ void CDisassembler::WriteFileBegin() { WritePublicsAndExternalsMASM(); break; case SUBTYPE_NASM: - WriteFileBeginYASM(); - WritePublicsAndExternalsYASMGASM(); + WriteFileBeginNASM(); + WritePublicsAndExternalsNASMGASM(); break; case SUBTYPE_GASM: WriteFileBeginGASM(); - WritePublicsAndExternalsYASMGASM(); + WritePublicsAndExternalsNASMGASM(); break; } } @@ -2625,8 +2625,8 @@ void CDisassembler::WriteFileBeginMASM() { OutFile.NewLine(); // Blank line } -void CDisassembler::WriteFileBeginYASM() { - // Write YASM-specific file init +void CDisassembler::WriteFileBeginNASM() { + // Write NASM-specific file init OutFile.NewLine(); if (WordSize == 64) { OutFile.Put("default rel"); OutFile.NewLine(); @@ -2795,8 +2795,8 @@ void CDisassembler::WritePublicsAndExternalsMASM() { } -void CDisassembler::WritePublicsAndExternalsYASMGASM() { - // Write public and external symbol definitions, YASM and GAS syntax +void CDisassembler::WritePublicsAndExternalsNASMGASM() { + // Write public and external symbol definitions, NASM and GAS syntax uint32_t i; // Loop counter uint32_t LinesWritten = 0; // Count lines written const char * XName; // Name of external symbols @@ -2991,7 +2991,7 @@ void CDisassembler::WriteSegmentBegin() { case SUBTYPE_MASM: WriteSegmentBeginMASM(); break; case SUBTYPE_NASM: - WriteSegmentBeginYASM(); break; + WriteSegmentBeginNASM(); break; case SUBTYPE_GASM: WriteSegmentBeginGASM(); break; } @@ -3094,7 +3094,7 @@ void CDisassembler::WriteSegmentBeginMASM() { } } -void CDisassembler::WriteSegmentBeginYASM() { +void CDisassembler::WriteSegmentBeginNASM() { // Write begin of segment OutFile.NewLine(); // Blank line @@ -3118,10 +3118,10 @@ void CDisassembler::WriteSegmentBeginYASM() { OutFile.PutDecimal(Sections[Section].WordSize); } if ((Sections[Section].Type & 0xFF) == 1) { - OutFile.Put(" execute"); + OutFile.Put(" exec"); } else { - OutFile.Put(" noexecute"); + OutFile.Put(" noexec"); } // Tabulate to comment @@ -3148,7 +3148,7 @@ void CDisassembler::WriteSegmentBeginYASM() { if (Sections[Section].Type & 0x1000) { // Communal OutFile.Put(CommentSeparator); - OutFile.Put(" Communal section not supported by YASM"); + OutFile.Put(" Communal section not supported by NASM"); OutFile.NewLine(); } } @@ -3285,7 +3285,7 @@ void CDisassembler::WriteFunctionBegin() { case SUBTYPE_MASM: WriteFunctionBeginMASM(SymI, Symbols[SymI].Scope); break; case SUBTYPE_NASM: - WriteFunctionBeginYASM(SymI, Symbols[SymI].Scope); break; + WriteFunctionBeginNASM(SymI, Symbols[SymI].Scope); break; case SUBTYPE_GASM: WriteFunctionBeginGASM(SymI, Symbols[SymI].Scope); break; } @@ -3332,8 +3332,8 @@ void CDisassembler::WriteFunctionBeginMASM(uint32_t symi, uint32_t scope) { OutFile.NewLine(); } -void CDisassembler::WriteFunctionBeginYASM(uint32_t symi, uint32_t scope) { - // Write begin of function, YASM syntax +void CDisassembler::WriteFunctionBeginNASM(uint32_t symi, uint32_t scope) { + // Write begin of function, NASM syntax // Write name WriteSymbolName(symi); // Colon @@ -3413,7 +3413,7 @@ void CDisassembler::WriteFunctionEnd() { case SUBTYPE_MASM: WriteFunctionEndMASM(SymNewI); break; case SUBTYPE_NASM: - WriteFunctionEndYASM(SymNewI); break; + WriteFunctionEndNASM(SymNewI); break; case SUBTYPE_GASM: WriteFunctionEndGASM(SymNewI); break; } @@ -3432,8 +3432,8 @@ void CDisassembler::WriteFunctionEndMASM(uint32_t symi) { OutFile.NewLine(); } -void CDisassembler::WriteFunctionEndYASM(uint32_t symi) { - // Write end of function, YASM syntax +void CDisassembler::WriteFunctionEndNASM(uint32_t symi) { + // Write end of function, NASM syntax // Write comment OutFile.Put(CommentSeparator); // Write name @@ -3487,7 +3487,7 @@ void CDisassembler::WriteCodeLabel(uint32_t symi) { case SUBTYPE_MASM: WriteCodeLabelMASM(symi, Symbols[symi].Scope); break; case SUBTYPE_NASM: - WriteCodeLabelYASM(symi, Symbols[symi].Scope); break; + WriteCodeLabelNASM(symi, Symbols[symi].Scope); break; case SUBTYPE_GASM: WriteCodeLabelGASM(symi, Symbols[symi].Scope); break; } @@ -3549,8 +3549,8 @@ void CDisassembler::WriteCodeLabelMASM(uint32_t symi, uint32_t scope) { } } -void CDisassembler::WriteCodeLabelYASM(uint32_t symi, uint32_t scope) { - // Write private or public code label, YASM syntax +void CDisassembler::WriteCodeLabelNASM(uint32_t symi, uint32_t scope) { + // Write private or public code label, NASM syntax if ((scope & 0xFF) > 2) { // Scope is public OutFile.NewLine(); @@ -3590,8 +3590,8 @@ void CDisassembler::WriteCodeLabelYASM(uint32_t symi, uint32_t scope) { } void CDisassembler::WriteCodeLabelGASM(uint32_t symi, uint32_t scope) { - // Write private or public code label, GAS syntax same as YASM syntax - WriteCodeLabelYASM(symi, scope); + // Write private or public code label, GAS syntax same as NASM syntax + WriteCodeLabelNASM(symi, scope); } void CDisassembler::WriteAssume() { diff --git a/src/elf2cof.cpp b/src/elf2cof.cpp index 978311f..1c0eae1 100755 --- a/src/elf2cof.cpp +++ b/src/elf2cof.cpp @@ -81,7 +81,10 @@ void CELF2COF::MakeSectionsIndex() { // Get section name const char * sname = ""; uint32_t namei = this->SectionHeaders[oldsec].sh_name; - if (namei >= this->SecStringTableLen) err.submit(2112); + + if (namei >= this->SecStringTableLen) { + err.submit(2112); + } else sname = this->SecStringTable + namei; if (cmd.DebugInfo == CMDL_DEBUG_STRIP) { @@ -149,7 +152,9 @@ void CELF2COF::MakeSections() { // Section name const char * sname = ""; uint32_t namei = OldHeader.sh_name; - if (namei >= this->SecStringTableLen) err.submit(2112); + if (namei >= this->SecStringTableLen) { + err.submit(2112); + } else sname = this->SecStringTable + namei; // Check for special names diff --git a/src/elf2elf.cpp b/src/elf2elf.cpp index 4b8e856..1f5c3de 100755 --- a/src/elf2elf.cpp +++ b/src/elf2elf.cpp @@ -1,13 +1,13 @@ /**************************** elf2elf.cpp ***************************** * Author: Agner Fog * Date created: 2006-01-13 -* Last modified: 2013-11-27 +* Last modified: 2022-08-31 * Project: objconv * Module: elf2elf.cpp * Description: * Module for changing symbol names in ELF file * -* Copyright 2006-2013 GNU General Public License http://www.gnu.org/licenses +* Copyright 2006-2022 GNU General Public License http://www.gnu.org/licenses *****************************************************************************/ #include "stdafx.h" // All functions in this module are templated to make two versions: 32 and 64 bits. @@ -27,30 +27,30 @@ template ::Convert() { // Some compilers require this-> for accessing members of template base class, // according to the so-called two-phase lookup rule. - MakeSymbolTable(); // Remake symbol tables and string tables - ChangeSections(); // Modify section names and relocation table symbol indices - MakeBinaryFile(); // Put everyting together into ToFile - *this << ToFile; // Take over new file buffer + MakeSymbolTable(); // Remake symbol tables and string tables + ChangeSections(); // Modify section names and relocation table symbol indices + MakeBinaryFile(); // Put everyting together into ToFile + *this << ToFile; // Take over new file buffer } // MakeSymbolTable() template void CELF2ELF::MakeSymbolTable() { - uint32_t SectionNumber; // Section number - char * SectionName; // Section name - uint32_t SecNamei; // Section name index - uint32_t OldSymi; // Old symbol index - uint32_t NewSymi; // New symbol index - int isymt; // 0 = symtab, 1 = dynsym - const char * name1; // Old name of symbol - const char * name2; // Changed name of symbol - int SymbolType; // Symbol type for cmd.SymbolChange - int action; // Symbol change action - int binding; // Symbol binding - TELF_Symbol sym; // Symbol table entry - TELF_Symbol AliasEntry; // Symbol table alias entry - uint32_t symnamei; // New symbol name index + uint32_t SectionNumber; // Section number + char * SectionName; // Section name + uint32_t SecNamei; // Section name index + uint32_t OldSymi; // Old symbol index + uint32_t NewSymi; // New symbol index + int isymt; // 0 = symtab, 1 = dynsym + const char * name1; // Old name of symbol + const char * name2; // Changed name of symbol + int SymbolType; // Symbol type for cmd.SymbolChange + int action; // Symbol change action + int binding; // Symbol binding + TELF_Symbol sym; // Symbol table entry + TELF_Symbol AliasEntry; // Symbol table alias entry + uint32_t symnamei; // New symbol name index CMemoryBuffer TempGlobalSymbolTable; // Temporary storage of public and external symbols // Find symbol table and string tables @@ -59,12 +59,12 @@ void CELF2ELF::MakeSymbolTable() { TELF_SectionHeader sheader = this->SectionHeaders[SectionNumber]; switch (sheader.sh_type) { case SHT_SYMTAB: - isymtab[0] = SectionNumber; // Symbol table found + isymtab[0] = SectionNumber; // Symbol table found istrtab[0] = this->SectionHeaders[SectionNumber].sh_link; // Associated string table break; case SHT_DYNSYM: - isymtab[1] = SectionNumber; // Dynamic symbol table found + isymtab[1] = SectionNumber; // Dynamic symbol table found istrtab[1] = this->SectionHeaders[SectionNumber].sh_link; // Associated string table break; @@ -74,13 +74,13 @@ void CELF2ELF::MakeSymbolTable() { err.submit(2112); return;} SectionName = this->SecStringTable + SecNamei; if (SectionNumber == this->FileHeader.e_shstrndx || !strcmp(SectionName,".shstrtab")) { - istrtab[2] = SectionNumber; // Section header string table found + istrtab[2] = SectionNumber; // Section header string table found } else if (!strcmp(SectionName,".strtab") && !istrtab[0]) { istrtab[0] = SectionNumber; // Symbol string table found } else if (!strcmp(SectionName,".stabstr")) { - istrtab[3] = SectionNumber; // Debug string table found + istrtab[3] = SectionNumber; // Debug string table found } break; } @@ -270,8 +270,14 @@ void CELF2ELF::ChangeSections() { TELF_Relocation * relocp; // Pointer to relocation entry uint32_t oldsymi, newsymi; // Relocation symbol index + uint32_t sectionSymtab = 2; // section string table index into NewStringTable + + if (istrtab[2] == istrtab[0]) { + sectionSymtab = 0; // sections and symbols use same table + } + // Initialize section header string table .shstrtab. First entry = 0 - NewStringTable[2].Push(0, 1); + NewStringTable[sectionSymtab].Push(0, 1); // Loop through sections SectionHeaderOffset = uint32_t(this->FileHeader.e_shoff); @@ -292,7 +298,7 @@ void CELF2ELF::ChangeSections() { // Store name in .shstrtab string table if (name1 && *name1) { - namei = NewStringTable[2].PushString(name1); + namei = NewStringTable[sectionSymtab].PushString(name1); } else { namei = 0; diff --git a/src/maindef.h b/src/maindef.h index 77b3e83..cbd6f73 100755 --- a/src/maindef.h +++ b/src/maindef.h @@ -1,7 +1,7 @@ /**************************** maindef.h ********************************** * Author: Agner Fog * Date created: 2006-08-26 -* Last modified: 2022-04-28 +* Last modified: 2022-08-31 * Project: objconv * Module: maindef.h * Description: @@ -13,7 +13,7 @@ #define MAINDEF_H // Program version -#define OBJCONV_VERSION 2.53 +#define OBJCONV_VERSION 2.54 // Integer type definitions with platform-independent sizes: diff --git a/src/proposed_improvements.txt b/src/proposed_improvements.txt new file mode 100755 index 0000000..ffd013f --- /dev/null +++ b/src/proposed_improvements.txt @@ -0,0 +1,15 @@ +Proposed improvements for objconv +================================= + +* Use container classes as intermediate format: +----------------------------------------------- +The conversion between different object file formats would be simpler +and easier to maintain if all sections, symbols, and relocations were +first stored in containers in the same way as is done for conversion +to assembly. The containers would be something like +CSList Sections; +CSList Relocations; +CSList SymbolList; + +However, I don't have the time for doing such a radical restructuring +of the code, and the need for conversion of object files is now quite low. From 22467aa219acbe836001857f4ab60af7cf970c8c Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 27 Nov 2023 12:05:58 -0600 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f982fc0..23b11be 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## objconv -This is a git mirror of [objconv](http://www.agner.org/optimize/), by Agner Fog. All rights belong to Agner Fog. As of this writing, this repository contains version 2.53 of objconv. +This is a git mirror of [objconv](http://www.agner.org/optimize/), by Agner Fog. All rights belong to Agner Fog. As of this writing, this repository contains version 2.54 of objconv. To regenerate this repository, run `./update.sh`.