#include "../ld/dwarf_defs.h"
#include "../ld/elf.h"
#include "../ld/macho.h"
+#include "../ld/pe.h"
/*
* Offsets and sizes of the debug_* sections in the cout file.
return sectionstart;
}
+static void
+align(vlong size)
+{
+ if((thechar == '6' || thechar == '8') && HEADTYPE == 10) // Only Windows PE need section align.
+ strnput("", rnd(size, PEFILEALIGN) - size);
+}
+
/*
* This is the main entry point for generating dwarf. After emitting
* the mandatory debug_abbrev section, it calls writelines() to set up
genasmsym(defdwsymb);
writeabbrev();
+ align(abbrevsize);
writelines();
+ align(linesize);
writeframes();
+ align(framesize);
synthesizestringtypes(dwtypes.child);
synthesizeslicetypes(dwtypes.child);
}
}
infosize = infoe - infoo;
+ align(infosize);
pubnameso = writepub(ispubname);
+ pubnamessize = cpos() - pubnameso;
+ align(pubnamessize);
+
pubtypeso = writepub(ispubtype);
+ pubtypessize = cpos() - pubtypeso;
+ align(pubtypessize);
+
arangeso = writearanges();
- gdbscripto = writegdbscript();
+ arangessize = cpos() - arangeso;
+ align(arangessize);
- pubnamessize = pubtypeso - pubnameso;
- pubtypessize = arangeso - pubtypeso;
- arangessize = gdbscripto - arangeso;
+ gdbscripto = writegdbscript();
gdbscriptsize = cpos() - gdbscripto;
+ align(gdbscriptsize);
}
/*
ms->filesize += msect->size;
}
}
+
+/*
+ * Windows PE
+ */
+void
+dwarfaddpeheaders(void)
+{
+ dwarfemitdebugsections();
+ newPEDWARFSection(".debug_abbrev", abbrevsize);
+ newPEDWARFSection(".debug_line", linesize);
+ newPEDWARFSection(".debug_frame", framesize);
+ newPEDWARFSection(".debug_info", infosize);
+ if (pubnamessize > 0)
+ newPEDWARFSection(".debug_pubnames", pubnamessize);
+ if (pubtypessize > 0)
+ newPEDWARFSection(".debug_pubtypes", pubtypessize);
+ if (arangessize > 0)
+ newPEDWARFSection(".debug_aranges", arangessize);
+ if (gdbscriptsize > 0)
+ newPEDWARFSection(".debug_gdb_scripts", gdbscriptsize);
+}
*/
void dwarfaddelfheaders(void);
void dwarfaddmachoheaders(void);
+void dwarfaddpeheaders(void);
#include "l.h"
#include "../ld/lib.h"
#include "../ld/pe.h"
+#include "../ld/dwarf.h"
// DOS stub that prints out
// "This program cannot be run in DOS mode."
0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
+static char symnames[256];
+static int nextsymoff;
+
int32 PESECTHEADR;
int32 PEFILEHEADR;
initdynimport();
}
+/*
+ * For more than 8 characters section names, name contains a slash (/) that is
+ * followed by an ASCII representation of a decimal number that is an offset into
+ * the string table.
+ * reference: pecoff_v8.docx Page 24.
+ * <http://www.microsoft.com/whdc/system/platform/firmware/PECOFFdwn.mspx>
+ */
+IMAGE_SECTION_HEADER*
+newPEDWARFSection(char *name, vlong size)
+{
+ IMAGE_SECTION_HEADER *h;
+ char s[8];
+
+ if(nextsymoff+strlen(name)+1 > sizeof(symnames)) {
+ diag("pe string table is full");
+ errorexit();
+ }
+
+ strcpy(&symnames[nextsymoff], name);
+ sprint(s, "/%d\0", nextsymoff+4);
+ nextsymoff += strlen(name);
+ symnames[nextsymoff] = 0;
+ nextsymoff ++;
+ h = addpesection(s, size, size, 0);
+ h->Characteristics = IMAGE_SCN_MEM_READ|
+ IMAGE_SCN_MEM_DISCARDABLE;
+
+ return h;
+}
+
+static void
+addsymtable(void)
+{
+ IMAGE_SECTION_HEADER *h;
+ int i, size;
+
+ if(nextsymoff == 0)
+ return;
+
+ size = nextsymoff + 4;
+ h = addpesection(".symtab", size, size, 0);
+ h->Characteristics = IMAGE_SCN_MEM_READ|
+ IMAGE_SCN_MEM_DISCARDABLE;
+ fh.PointerToSymbolTable = cpos();
+ fh.NumberOfSymbols = 0;
+ // put symbol string table
+ lputl(size);
+ for (i=0; i<nextsymoff; i++)
+ cput(symnames[i]);
+ strnput("", h->SizeOfRawData - size);
+ cflush();
+}
+
+
void
asmbpe(void)
{
IMAGE_SCN_MEM_READ|IMAGE_SCN_MEM_WRITE;
addimports(nextfileoff, d);
+
+ if(!debug['s'])
+ dwarfaddpeheaders();
+ addsymtable();
+
fh.NumberOfSections = nsect;
fh.TimeDateStamp = time(0);
fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED|
pewrite();
}
+
IMAGE_SCN_MEM_EXECUTE = 0x20000000,
IMAGE_SCN_MEM_READ = 0x40000000,
IMAGE_SCN_MEM_WRITE = 0x80000000,
+ IMAGE_SCN_MEM_DISCARDABLE = 0x2000000,
IMAGE_DIRECTORY_ENTRY_EXPORT = 0,
IMAGE_DIRECTORY_ENTRY_IMPORT = 1,
void asmbpe(void);
void dope(void);
+IMAGE_SECTION_HEADER* newPEDWARFSection(char *name, vlong size);
+
// X64
typedef struct {
uint16 Magic;