Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 9a8edfb

Browse files
authored
Merge pull request #2236 from wilzbach/merge_stable
Merge remote-tracking branch 'upstream/stable' into merge_stable
2 parents 8fd5201 + da0c5fa commit 9a8edfb

36 files changed

+101
-38
lines changed

src/core/internal/string.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright: Copyright Sean Kelly 2005 - 2009.
55
* License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
66
* Authors: Sean Kelly, Walter Bright
7-
* Source: $(DRUNTIMESRC src/rt/util/_string.d)
7+
* Source: $(DRUNTIMESRC rt/util/_string.d)
88
*/
99

1010
module core.internal.string;

src/rt/aApply.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright: Copyright Digital Mars 2004 - 2010.
77
* License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
88
* Authors: Walter Bright
9-
* Source: $(DRUNTIMESRC src/rt/_aApply.d)
9+
* Source: $(DRUNTIMESRC rt/_aApply.d)
1010
*/
1111
module rt.aApply;
1212

src/rt/adi.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
77
* (See accompanying file LICENSE)
88
* Authors: Walter Bright
9-
* Source: $(DRUNTIMESRC src/rt/_adi.d)
9+
* Source: $(DRUNTIMESRC rt/_adi.d)
1010
*/
1111

1212
module rt.adi;

src/rt/alloca.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
77
* (See accompanying file LICENSE)
88
* Authors: Walter Bright
9-
* Source: $(DRUNTIMESRC src/rt/_alloca.d)
9+
* Source: $(DRUNTIMESRC rt/_alloca.d)
1010
*/
1111

1212
module rt.alloca;

src/rt/arrayassign.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* License: Distributed under the
77
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
88
* Authors: Walter Bright, Kenji Hara
9-
* Source: $(DRUNTIMESRC src/rt/_arrayassign.d)
9+
* Source: $(DRUNTIMESRC rt/_arrayassign.d)
1010
*/
1111

1212
module rt.arrayassign;

src/rt/arraycast.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* License: Distributed under the
66
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
77
* Authors: Walter Bright, Sean Kelly
8-
* Source: $(DRUNTIMESRC src/rt/_arraycast.d)
8+
* Source: $(DRUNTIMESRC rt/_arraycast.d)
99
*/
1010

1111
module rt.arraycast;

src/rt/arraycat.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* License: Distributed under the
66
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
77
* Authors: Walter Bright, Sean Kelly
8-
* Source: $(DRUNTIMESRC src/rt/_arraycat.d)
8+
* Source: $(DRUNTIMESRC rt/_arraycat.d)
99
*/
1010

1111
module rt.arraycat;

src/rt/backtrace/dwarf.d

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright: Copyright Digital Mars 2015 - 2015.
88
* License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
99
* Authors: Yazan Dabain, Sean Kelly
10-
* Source: $(DRUNTIMESRC src/rt/backtrace/dwarf.d)
10+
* Source: $(DRUNTIMESRC rt/backtrace/dwarf.d)
1111
*/
1212

1313
module rt.backtrace.dwarf;
@@ -72,7 +72,7 @@ int traceHandlerOpApplyImpl(const void*[] callstack, scope int delegate(ref size
7272
foreach(size_t i; 0 .. callstack.length)
7373
locations[i].address = cast(size_t) callstack[i];
7474

75-
resolveAddresses(debugLineSectionData, locations[]);
75+
resolveAddresses(debugLineSectionData, locations[], image.baseAddress);
7676
}
7777
}
7878

@@ -108,7 +108,7 @@ int traceHandlerOpApplyImpl(const void*[] callstack, scope int delegate(ref size
108108
private:
109109

110110
// the lifetime of the Location data is the lifetime of the mmapped ElfSection
111-
void resolveAddresses(const(ubyte)[] debugLineSectionData, Location[] locations) @nogc nothrow
111+
void resolveAddresses(const(ubyte)[] debugLineSectionData, Location[] locations, size_t baseAddress) @nogc nothrow
112112
{
113113
debug(DwarfDebugMachine) import core.stdc.stdio;
114114

@@ -202,6 +202,9 @@ void resolveAddresses(const(ubyte)[] debugLineSectionData, Location[] locations)
202202
runStateMachine(lph, program, standardOpcodeLengths,
203203
(size_t address, LocationInfo locInfo, bool isEndSequence)
204204
{
205+
// adjust to ASLR offset
206+
address += baseAddress;
207+
debug(DwarfDebugMachine) printf("-- offsetting 0x%x to 0x%x\n", address - baseAddress, address);
205208
// If loc.line != -1, then it has been set previously.
206209
// Some implementations (eg. dmd) write an address to
207210
// the debug data multiple times, but so far I have found

src/rt/backtrace/elf.d

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright: Copyright Digital Mars 2015 - 2015.
77
* License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
88
* Authors: Yazan Dabain
9-
* Source: $(DRUNTIMESRC src/rt/backtrace/elf.d)
9+
* Source: $(DRUNTIMESRC rt/backtrace/elf.d)
1010
*/
1111

1212
module rt.backtrace.elf;
@@ -61,6 +61,61 @@ struct Image
6161

6262
return null;
6363
}
64+
65+
@property size_t baseAddress()
66+
{
67+
version(linux)
68+
{
69+
import core.sys.linux.link;
70+
import core.sys.linux.elf;
71+
}
72+
else version(FreeBSD)
73+
{
74+
import core.sys.freebsd.sys.link_elf;
75+
import core.sys.freebsd.sys.elf;
76+
}
77+
else version(DragonFlyBSD)
78+
{
79+
import core.sys.dragonflybsd.sys.link_elf;
80+
import core.sys.dragonflybsd.sys.elf;
81+
}
82+
83+
static struct ElfAddress
84+
{
85+
size_t begin;
86+
bool set;
87+
}
88+
ElfAddress elfAddress;
89+
90+
// the DWARF addresses for DSOs are relative
91+
const isDynamicSharedObject = (file.ehdr.e_type == ET_DYN);
92+
if (!isDynamicSharedObject)
93+
return 0;
94+
95+
extern(C) int dl_iterate_phdr_cb_ngc_tracehandler(dl_phdr_info* info, size_t, void* elfObj) @nogc
96+
{
97+
auto obj = cast(ElfAddress*) elfObj;
98+
// only take the first address as this will be the main binary
99+
if (obj.set)
100+
return 0;
101+
102+
obj.set = true;
103+
// search for the executable code segment
104+
foreach (const ref phdr; info.dlpi_phdr[0 .. info.dlpi_phnum])
105+
{
106+
if (phdr.p_type == PT_LOAD && phdr.p_flags & PF_X)
107+
{
108+
obj.begin = info.dlpi_addr + phdr.p_vaddr;
109+
return 0;
110+
}
111+
}
112+
// fall back to the base address of the object file
113+
obj.begin = info.dlpi_addr;
114+
return 0;
115+
}
116+
dl_iterate_phdr(&dl_iterate_phdr_cb_ngc_tracehandler, &elfAddress);
117+
return elfAddress.begin;
118+
}
64119
}
65120

66121
private:

src/rt/backtrace/macho.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright: Copyright Jacob Carlborg 2018.
55
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
66
* Authors: Jacob Carlborg
7-
* Source: $(DRUNTIMESRC src/rt/backtrace/macho.d)
7+
* Source: $(DRUNTIMESRC rt/backtrace/macho.d)
88
*/
99
module rt.backtrace.macho;
1010

@@ -67,4 +67,9 @@ struct Image
6767
auto data = getsectiondata(self, "__DWARF", "__debug_line", &size);
6868
return data[0 .. size];
6969
}
70+
71+
@property size_t baseAddress()
72+
{
73+
return 0;
74+
}
7075
}

0 commit comments

Comments
 (0)