Skip to content

Commit

Permalink
make shndx_data a value rather than a pointer (#16660)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored Jul 5, 2024
1 parent eccb2ca commit 11fb8c3
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions compiler/src/dmd/backend/elfobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct ElfObj
int symbol_idx; // Number of symbols in symbol table
int local_cnt; // Number of symbols with STB_LOCAL

OutBuffer* shndx_data; // Extended section header indices
OutBuffer shndx_data; // Extended section header indices

OutBuffer* note_data; // Notes data (note currently used)

Expand Down Expand Up @@ -373,13 +373,7 @@ private IDXSYM elf_addsym(IDXSTR nam, targ_size_t val, uint sz,
if (sec > SHN_HIRESERVE)
{ // If the section index is too big we need to store it as
// extended section header index.
if (!elfobj.shndx_data)
{
elfobj.shndx_data = cast(OutBuffer*) calloc(1, OutBuffer.sizeof);
if (!elfobj.shndx_data)
err_nomem();
elfobj.shndx_data.reserve(50 * (Elf64_Word).sizeof);
}

// fill with zeros up to symbol_idx
const size_t shndx_idx = elfobj.shndx_data.length() / Elf64_Word.sizeof;
elfobj.shndx_data.writezeros(cast(uint)((elfobj.symbol_idx - shndx_idx) * Elf64_Word.sizeof));
Expand Down Expand Up @@ -732,8 +726,8 @@ Obj ElfObj_init(OutBuffer *objbuf, const(char)* filename, const(char)* csegname)
symbol_reset(*s);
elfobj.resetSyms.reset();

if (elfobj.shndx_data)
elfobj.shndx_data.reset();
elfobj.shndx_data.reset();
elfobj.shndx_data.reserve(50 * (Elf64_Word).sizeof);

if (elfobj.note_data)
elfobj.note_data.reset();
Expand Down Expand Up @@ -893,7 +887,7 @@ void *elf_renumbersyms()
}

// Reorder extended section header indices
if (elfobj.shndx_data && elfobj.shndx_data.length())
if (elfobj.shndx_data.length())
{
// fill with zeros up to symbol_idx
const size_t shndx_idx = elfobj.shndx_data.length() / Elf64_Word.sizeof;
Expand Down Expand Up @@ -1113,7 +1107,7 @@ void ElfObj_term(const(char)[] objfilename)
foffset += sechdr.sh_size;
util_free(symtab);

if (elfobj.shndx_data && elfobj.shndx_data.length())
if (elfobj.shndx_data.length())
{
assert(elfobj.SecHdrTab.length >= secidx_shndx);
sechdr = &elfobj.SecHdrTab[secidx_shndx];
Expand Down

0 comments on commit 11fb8c3

Please sign in to comment.