Skip to content

Commit 0655f30

Browse files
authored
Merge pull request #61 from opendlang/upstreamstuff
Upstream stuff
2 parents 5b2749a + 7037589 commit 0655f30

23 files changed

Lines changed: 523 additions & 177 deletions

compiler/src/build.d

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,15 @@ void parseEnvironment()
12001200

12011201
// detect Model
12021202
auto model = env.setDefault("MODEL", detectModel);
1203-
env["MODEL_FLAG"] = "-m" ~ env["MODEL"];
1203+
if (env.getDefault("DFLAGS", "").canFind("-mtriple", "-march"))
1204+
{
1205+
// Don't pass `-m32|64` flag when explicitly passing triple or arch.
1206+
env["MODEL_FLAG"] = "";
1207+
}
1208+
else
1209+
{
1210+
env["MODEL_FLAG"] = "-m" ~ env["MODEL"];
1211+
}
12041212

12051213
// detect PIC
12061214
version(Posix)
@@ -1690,7 +1698,7 @@ string detectModel()
16901698
else
16911699
uname = ["uname", "-m"].execute.output;
16921700

1693-
if (uname.canFind("x86_64", "amd64", "64-bit", "64-Bit", "64 bit"))
1701+
if (uname.canFind("x86_64", "amd64", "arm64", "64-bit", "64-Bit", "64 bit"))
16941702
return "64";
16951703
if (uname.canFind("i386", "i586", "i686", "32-bit", "32-Bit", "32 bit"))
16961704
return "32";
@@ -2348,31 +2356,5 @@ void copyAndTouch(const string from, const string to)
23482356
to.setTimes(now, now);
23492357
}
23502358

2351-
version (OSX)
2352-
{
2353-
// FIXME: Parallel executions hangs reliably on Mac (esp. the 'macair'
2354-
// host used by the autotester) for unknown reasons outside of this script.
2355-
pragma(msg, "Warning: Syncing file access because of OSX!");
2356-
2357-
// Wrap standard library functions to ensure mutually exclusive file access
2358-
alias readText = fileAccess!(std.file.readText, string);
2359-
alias writeText = fileAccess!(std.file.write, string, string);
2360-
alias timeLastModified = fileAccess!(std.file.timeLastModified, string);
2361-
2362-
import core.sync.mutex;
2363-
__gshared Mutex fileAccessMutex;
2364-
shared static this() {
2365-
fileAccessMutex = new Mutex();
2366-
}
2367-
2368-
auto fileAccess(alias dg, T...)(T args)
2369-
{
2370-
fileAccessMutex.lock_nothrow();
2371-
scope (exit) fileAccessMutex.unlock_nothrow();
2372-
return dg(args);
2373-
}
2374-
}
2375-
else
2376-
{
2377-
alias writeText = std.file.write;
2378-
}
2359+
// Wrap standard library functions
2360+
alias writeText = std.file.write;

compiler/src/dmd/backend/dwarfdbginf.d

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616
Some generic information for debug info on macOS:
1717
1818
The linker on macOS will remove any debug info, i.e. every section with the
19-
`S_ATTR_DEBUG` flag, this includes everything in the `__DWARF` section. By using
20-
the `S_REGULAR` flag the linker will not remove this section. This allows to get
21-
the filenames and line numbers for backtraces from the executable.
19+
`S_ATTR_DEBUG` flag, this includes everything in the `__DWARF` section.
20+
Because of this, it is not possible to get filenames and line numbers for
21+
backtraces from the executable alone.
2222
2323
Normally the linker removes all the debug info but adds a reference to the
2424
object files. The debugger can then read the object files to get filename and
2525
line number information. It's also possible to use an additional tool that
2626
generates a separate `.dSYM` file. This file can then later be deployed with the
2727
application if debug info is needed when the application is deployed.
28+
29+
Support in core.runtime for getting filename and line number for backtraces
30+
from these `.dSYM` files will need to be investigated.
31+
See: https://issues.dlang.org/show_bug.cgi?id=20510
2832
*/
2933

3034
module dmd.backend.dwarfdbginf;
@@ -476,7 +480,7 @@ static if (1)
476480
{
477481
name = n;
478482
if (config.objfmt == OBJ_MACH)
479-
flags = S_ATTR_DEBUG;
483+
flags = S_REGULAR | S_ATTR_DEBUG;
480484
else
481485
flags = SHT_PROGBITS;
482486
}
@@ -550,10 +554,7 @@ static if (1)
550554
debug_abbrev = Section("__debug_abbrev");
551555
debug_info = Section("__debug_info");
552556
debug_str = Section("__debug_str");
553-
// We use S_REGULAR to make sure the linker doesn't remove this section. Needed
554-
// for filenames and line numbers in backtraces.
555557
debug_line = Section("__debug_line");
556-
debug_line.flags = S_REGULAR;
557558
}
558559
void elfDebugSectionsInit()
559560
{

compiler/src/dmd/backend/mach.d

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ enum
9494
LC_SYMTAB = 2,
9595
LC_DYSYMTAB = 11,
9696
LC_SEGMENT_64 = 0x19,
97+
98+
/// Build for MacOSX min OS version.
99+
LC_VERSION_MIN_MACOSX = 0x24,
100+
101+
/// Build for platform min OS version.
102+
LC_BUILD_VERSION = 0x32,
97103
}
98104

99105
struct load_command
@@ -407,3 +413,62 @@ struct scattered_relocation_info
407413

408414
int r_value;
409415
}
416+
417+
/**
418+
* The version_min_command contains the min OS version on which this binary was
419+
* built to run.
420+
*/
421+
struct version_min_command
422+
{
423+
///
424+
uint cmd = LC_VERSION_MIN_MACOSX;
425+
426+
///
427+
uint cmdsize = typeof(this).sizeof;
428+
429+
/// X.Y.Z is encoded in nibbles xxxx.yy.zz
430+
uint version_;
431+
432+
/// X.Y.Z is encoded in nibbles xxxx.yy.zz
433+
uint sdk = 0;
434+
}
435+
436+
/**
437+
* The `build_version_command` contains the min OS version on which this binary
438+
* was built to run for its platform.
439+
*/
440+
struct build_version_command
441+
{
442+
///
443+
uint cmd = LC_BUILD_VERSION;
444+
445+
///
446+
uint cmdsize = typeof(this).sizeof;
447+
448+
/// Platform
449+
uint platform = PLATFORM_MACOS;
450+
451+
/// X.Y.Z is encoded in nibbles xxxx.yy.zz
452+
uint minos;
453+
454+
/// X.Y.Z is encoded in nibbles xxxx.yy.zz
455+
uint sdk = 0;
456+
457+
/// Number of tool entries following this
458+
uint ntools = 0;
459+
}
460+
461+
/// Known values for the platform field in `build_version_command`
462+
enum
463+
{
464+
PLATFORM_MACOS = 1,
465+
PLATFORM_IOS = 2,
466+
PLATFORM_TVOS = 3,
467+
PLATFORM_WATCHOS = 4,
468+
PLATFORM_BRIDGEOS = 5,
469+
PLATFORM_MACCATALYST = 6,
470+
PLATFORM_IOSSIMULATOR = 7,
471+
PLATFORM_TVOSSIMULATOR = 8,
472+
PLATFORM_WATCHOSSIMULATOR = 9,
473+
PLATFORM_DRIVERKIT = 10
474+
}

0 commit comments

Comments
 (0)