Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
23 changes: 13 additions & 10 deletions compiler/src/dmd/backend/backconfig.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void out_config_init(
bool useModuleInfo,
bool useTypeInfo,
bool useExceptions,
bool unwindTables,
ubyte dwarf,
string _version,
exefmt_t exefmt,
Expand Down Expand Up @@ -159,15 +160,16 @@ void out_config_init(
cfg.avx = avx;
if (model == 64)
{
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
}
else
{
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
if (!exe)
cfg.flags |= CFGromable; // put switch tables in code segment
}
cfg.flags |= CFGnoebp;
if (!unwindTables)
cfg.flags |= CFGnoebp;
switch (pic)
{
case 0: // PIC.fixed
Expand All @@ -193,7 +195,7 @@ void out_config_init(
{
cfg.fpxmmregs = true;
cfg.avx = avx;
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.flags |= CFGnoebp;
if (!exe)
{
Expand All @@ -211,13 +213,13 @@ void out_config_init(
{
if (model == 64)
{
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.fpxmmregs = true;
cfg.avx = avx;
}
else
{
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
if (!exe)
cfg.flags |= CFGromable; // put switch tables in code segment
}
Expand Down Expand Up @@ -247,13 +249,13 @@ void out_config_init(
if (!exe)
cfg.flags3 |= CFG3pic;
cfg.objfmt = OBJ_ELF;
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
}
if (cfg.exe == EX_DRAGONFLYBSD64)
{
if (model == 64)
{
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.fpxmmregs = true;
cfg.avx = avx;
}
Expand Down Expand Up @@ -286,7 +288,7 @@ void out_config_init(
if (!exe)
cfg.flags3 |= CFG3pic;
cfg.objfmt = OBJ_ELF;
cfg.ehmethod = useExceptions ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
cfg.ehmethod = (useExceptions || unwindTables) ? EHmethod.EH_DWARF : EHmethod.EH_NONE;
}

cfg.flags2 |= CFG2nodeflib; // no default library
Expand Down Expand Up @@ -357,7 +359,8 @@ static if (0)

cfg.useModuleInfo = useModuleInfo;
cfg.useTypeInfo = useTypeInfo;
cfg.useExceptions = useExceptions;
cfg.useExceptions = useExceptions || unwindTables;
cfg.unwindTables = unwindTables;

cod3_setdefault();
if (arm)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/backend/cdef.d
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ struct Config
bool useModuleInfo; // implement ModuleInfo
bool useTypeInfo; // implement TypeInfo
bool useExceptions; // implement exception handling
bool unwindTables; // emit unwind tables for stack tracing
ubyte dwarf; // DWARF version
}

Expand Down
25 changes: 17 additions & 8 deletions compiler/src/dmd/backend/dwarfdbginf.d
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,20 @@ static if (1)
*/
bool doUnwindEhFrame()
{
if (funcsym_p.Sfunc.Fflags3 & Feh_none)
{
return (config.exe & (EX_FREEBSD | EX_FREEBSD64 | EX_OPENBSD | EX_OPENBSD64 | EX_DRAGONFLYBSD64)) != 0;
}

/* FreeBSD fails when having some frames as having unwinding info and some not.
* (It hangs in unittests for std.datetime.)
* g++ on FreeBSD does not generate mixed frames, while g++ on OSX and Linux does.
*/
assert(!(cgstate.usednteh & ~(EHtry | EHcleanup)));

if (config.unwindTables)
return true;

if (funcsym_p.Sfunc.Fflags3 & Feh_none)
{
return (config.exe & (EX_FREEBSD | EX_FREEBSD64 | EX_OPENBSD | EX_OPENBSD64 | EX_DRAGONFLYBSD64)) != 0;
}

return (cgstate.usednteh & (EHtry | EHcleanup)) ||
(config.exe & (EX_FREEBSD | EX_FREEBSD64 | EX_OPENBSD | EX_OPENBSD64 | EX_DRAGONFLYBSD64)) && config.useExceptions;
}
Expand Down Expand Up @@ -1759,11 +1763,16 @@ static if (1)
OutBuffer* buf = SegData[dfseg].SDbuf;
buf.reserve(1000);

uint* poffset = ehunwind ? &CIE_offset_unwind : &CIE_offset_no_unwind;
// When unwind tables are enabled, don't reference personality function (no druntime)
bool usePersonality = ehunwind && !config.unwindTables;
uint* poffset = usePersonality ? &CIE_offset_unwind : &CIE_offset_no_unwind;
if (*poffset == ~0)
*poffset = writeEhFrameHeader(dfseg, buf, getRtlsymPersonality(), ehunwind);
{
Symbol* personality = usePersonality ? getRtlsymPersonality() : null;
*poffset = writeEhFrameHeader(dfseg, buf, personality, usePersonality);
}

writeEhFrameFDE(dfseg, sfunc, ehunwind, *poffset);
writeEhFrameFDE(dfseg, sfunc, usePersonality, *poffset);
}
if (!config.fulltypes)
return;
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/backend/x86/cgcod.d
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ void prolog(ref CGstate cg, ref CodeBuilder cdb)
* so need frame if function can possibly throw
*/
!(config.exe == EX_WIN32) && !(funcsym_p.Sfunc.Fflags3 & Fnothrow) ||
(config.unwindTables && config.ehmethod == EHmethod.EH_DWARF) ||
cg.accessedTLS ||
sv64 ||
(0 && cg.calledafunc && cg.AArch64)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/dmdparams.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum SymImport : ubyte
struct DMDparams
{
bool alwaysframe; // always emit standard stack frame
bool unwindTables; // emit unwind tables for stack tracing
ubyte dwarf; // DWARF version
bool map; // generate linker .map file
bool vasm; // print generated assembler for each function
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dmd/dmsc.d
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void backend_init(const ref Param params, const ref DMDparams driverParams, cons
driverParams.pic,
params.useModuleInfo && Module.moduleinfo,
params.useTypeInfo && Type.dtypeinfo,
params.useExceptions && ClassDeclaration.throwable,
params.useExceptions && (ClassDeclaration.throwable || driverParams.unwindTables),
driverParams.unwindTables,
driverParams.dwarf,
global.versionString(),
exfmt,
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ extern (C++) struct Param
bool useExceptions = true; // support exception handling
bool useGC = true; // support features that require the D runtime GC
bool betterC; // be a "better C" compiler; no dependency on D runtime
bool unwindTables; // emit unwind tables for stack tracing (-gu)
bool addMain; // add a default main() function
bool allInst; // generate code for all template instantiations
bool bitfields = true; // support C style bit fields
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ struct Param
d_bool useExceptions; // support exception handling
d_bool useGC; // support features that require the D runtime GC
d_bool betterC; // be a "better C" compiler; no dependency on D runtime
d_bool unwindTables; // emit unwind tables for stack tracing (-gu)
d_bool addMain; // add a default main() function
d_bool allInst; // generate code for all template instantiations
d_bool bitfields; // support C style bit fields
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/glue/toir.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ struct IRState
this.params = params;
this.target = target;
this.eSink = eSink;
mayThrow = params.useExceptions
&& ClassDeclaration.throwable
&& !(fd && fd.hasNoEH);
bool exceptionsEnabled = params.useExceptions &&
(ClassDeclaration.throwable || params.unwindTables);
mayThrow = exceptionsEnabled && !(fd && fd.hasNoEH);
this.Cfile = m.filetype == FileType.c;
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,11 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, out Param
}
else if (arg == "-gs") // https://dlang.org/dmd.html#switch-gs
driverParams.alwaysframe = true;
else if (arg == "-gu") // https://dlang.org/dmd.html#switch-gu
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW that needs an update to src/dmd/cli.d

{
driverParams.unwindTables = true;
global.params.unwindTables = true;
}
else if (arg == "-gx") // https://dlang.org/dmd.html#switch-gx
driverParams.stackstomp = true;
else if (arg == "-lowmem") // https://dlang.org/dmd.html#switch-lowmem
Expand Down
Loading