Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dmd/backend/code.d
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ alias IDXSTR = uint;
alias IDXSEC = uint;
alias IDXSYM = uint;

struct seg_data
struct seg_data // SegData is an array of these, indexed by segment index
{
segidx_t SDseg; // index into SegData[]
targ_size_t SDoffset; // starting offset for data
Expand All @@ -275,8 +275,9 @@ struct seg_data
}

//ELFOBJ || MACHOBJ
IDXSEC SDshtidx; // section header table index into SECbuf[]
OutBuffer *SDbuf; // buffer to hold data
IDXSEC SDshtidx; // ELFOBJ : index into SecHdrTab[]
// MACHOBJ: index into section_64s[] or sections[]
OutBuffer *SDbuf; // buffer to hold segment data
// union
// struct
// {
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/backend/dwarfdbginf.d
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,7 @@ static if (1)
return;

int seg = dwarf_except_table_alloc(sfunc);
//printf("seg: %d except_table_seg: %d\n", seg, except_table_seg);
OutBuffer* buf = SegData[seg].SDbuf;
buf.reserve(100);

Expand Down
8 changes: 6 additions & 2 deletions compiler/src/dmd/backend/dwarfeh.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ void genDwarfEh(Funcsym* sfunc, int seg, OutBuffer* et, bool scancode, uint star

et.reserve(100);
block* startblock = sfunc.Sfunc.Fstartblock;
//printf("genDwarfEh: func = %s, offset = x%x, startblock.Boffset = x%x, scancode = %d startoffset=x%x, retoffset=x%x\n",
//sfunc.Sident.ptr, cast(int)sfunc.Soffset, cast(int)startblock.Boffset, scancode, startoffset, retoffset);
static if (0)
printf("genDwarfEh: sfunc: %s seg: %d offset: x%x startblock.Boffset: x%x, scancode: %d startoffset: x%x retoffset: x%x\n",
sfunc.Sident.ptr, seg, cast(int)sfunc.Soffset, cast(int)startblock.Boffset, scancode, startoffset, retoffset);

static if (0)
{
Expand Down Expand Up @@ -341,7 +342,10 @@ else
if (config.objfmt == OBJ_ELF)
elf_dwarf_reftoident(seg, et.length(), s, 0);
else if (config.objfmt == OBJ_MACH)
{
assert(et == SegData[seg].SDbuf);
mach_dwarf_reftoident(seg, et.length(), s, 0);
}
}
assert(TToffset == et.length() - startsize);
}
Expand Down
28 changes: 20 additions & 8 deletions compiler/src/dmd/backend/machobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,18 @@ void MachObj_termfile()
}
}

static if (0)
void segsizes() @trusted
{
printf("Segsizes\n");
for (int seg = 1; seg < SegData.length; seg++)
{
seg_data* pseg = SegData[seg];
if (pseg.SDbuf && pseg.SDbuf.length())
printf("\tpseg: %p SDbuf: %p %d SDbuf.length %zx\n", pseg, pseg.SDbuf, seg, pseg.SDbuf.length());
}
}

/*********************************
* Terminate package.
*/
Expand All @@ -618,7 +630,6 @@ void MachObj_term(const(char)[] objfilename)
dwarf_termfile();
}


/* Write out the object file in the following order:
* header
* commands
Expand Down Expand Up @@ -787,7 +798,7 @@ void MachObj_term(const(char)[] objfilename)
foreach (i, s; table)
printf("table[%d] = %d %d\n", cast(int)i, table[i], table[table[i]]);

//printf("Setup offsets and sizes foffset %d\n\tsection_length %d, SegData.length %d\n",foffset,section_length,SegData.length);
//printf("\nSetup offsets and sizes foffset %d\n\tSegData.length %zx\n",foffset,SegData.length);
{
/* For each segment, write the segment data bytes out to fobjbuf */
for (int seg = 1; seg < SegData.length; seg++)
Expand All @@ -810,16 +821,16 @@ void MachObj_term(const(char)[] objfilename)
{
psechdr.offset = 0;
psechdr.size = pseg.SDoffset; // accumulated size
//printf("\tzero section name %s size %d\n", psechdr.sectname.ptr, cast(int)pseg.SDoffset);
//printf("\tzero section name %s size %zx\n", psechdr.sectname.ptr, pseg.SDoffset);
}
else
{
psechdr.offset = foffset;
psechdr.size = 0;
//printf("\tsection name %s,", psechdr.sectname.ptr);
//printf("\t%d section name %s,", table[seg], psechdr.sectname.ptr);
if (pseg.SDbuf && pseg.SDbuf.length())
{
//printf("\tsize %d\n", cast(int)pseg.SDbuf.length());
//printf("\tSDbuf.length %zx\n", pseg.SDbuf.length());
psechdr.size = pseg.SDbuf.length();
machobj.fobjbuf.write(pseg.SDbuf.buf, cast(uint)psechdr.size);
foffset += psechdr.size;
Expand Down Expand Up @@ -3257,7 +3268,7 @@ int MachObj_reftoidentAArch64(int seg, targ_size_t offset, Symbol* s, targ_size_
if (log)
{
debug printf("\nMachObj_reftoidentAArch64('%s' seg %d, offset x%llx, val x%llx, flags x%x) ",
s.Sident.ptr,seg,cast(ulong)offset,cast(ulong)val,flags);
s.Sident.ptr,seg,offset,val,flags);
//CF_print(flags);
//debug printf("retsize = %d\n", retsize);
//dbg_printf("Sseg = %d, Sxtrnnum = %d\n",s.Sseg,s.Sxtrnnum);
Expand Down Expand Up @@ -3315,7 +3326,7 @@ int MachObj_reftoidentAArch64(int seg, targ_size_t offset, Symbol* s, targ_size_
}
else
buf.write64(val);
if (save > offset + retsize)
if (save >= offset + retsize)
buf.setsize(save);

return retsize;
Expand Down Expand Up @@ -3460,7 +3471,8 @@ int mach_dwarf_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t va
{
//printf("dwarf_reftoident(seg=%d offset=x%x s=%s val=x%x\n", seg, cast(int)offset, s.Sident.ptr, cast(int)val);
if (machobj.AArch64)
MachObj_reftoident(seg, offset, s, val + 4, CF.selfrel);
//MachObj_reftoident(seg, offset, s, val + 4, CF.selfrel);
MachObj_reftoident(seg, offset, s, val + 4, CF.off);
else
MachObj_reftoident(seg, offset, s, val + 4, I64 ? CF.off : CF.indirect);
return 4;
Expand Down
Loading