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

Commit e18c21a

Browse files
Merge pull request #2713 from jacob-carlborg/fix-dylibs-macos
Fix shared libraries for LDC on macOS
2 parents bb0bce7 + 68abebb commit e18c21a

File tree

5 files changed

+43
-46
lines changed

5 files changed

+43
-46
lines changed

mak/DOCS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@ DOCS=\
162162
$(DOCDIR)\rt_util_container_common.html \
163163
$(DOCDIR)\rt_util_container_hashtab.html \
164164
$(DOCDIR)\rt_util_container_treap.html \
165+
$(DOCDIR)\rt_util_utility.html \
165166
$(DOCDIR)\rt_util_random.html \
166167
$(DOCDIR)\rt_util_typeinfo.html \

mak/SRCS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ SRCS=\
458458
src\rt\util\array.d \
459459
src\rt\util\random.d \
460460
src\rt\util\typeinfo.d \
461+
src\rt\util\utility.d \
461462
src\rt\util\container\array.d \
462463
src\rt\util\container\common.d \
463464
src\rt\util\container\hashtab.d \

src/rt/sections_elf_shared.d

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,7 @@ import rt.dmain2;
5959
import rt.minfo;
6060
import rt.util.container.array;
6161
import rt.util.container.hashtab;
62-
63-
/****
64-
* Asserts the specified condition, independent from -release, by abort()ing.
65-
* Regular assertions throw an AssertError and thus require an initialized
66-
* GC, which isn't the case (yet or anymore) for the startup/shutdown code in
67-
* this module (called by CRT ctors/dtors etc.).
68-
*/
69-
private void safeAssert(bool condition, scope string msg, size_t line = __LINE__) @nogc nothrow @safe
70-
{
71-
import core.internal.abort;
72-
condition || abort(msg, __FILE__, line);
73-
}
62+
import rt.util.utility : safeAssert;
7463

7564
alias DSO SectionGroup;
7665
struct DSO

src/rt/sections_osx_x86_64.d

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import core.stdc.string, core.stdc.stdlib;
2929
import core.sys.posix.pthread;
3030
import core.sys.darwin.mach.dyld;
3131
import core.sys.darwin.mach.getsect;
32+
3233
import rt.deh, rt.minfo;
3334
import rt.util.container.array;
35+
import rt.util.utility : safeAssert;
3436

3537
struct SectionGroup
3638
{
@@ -95,9 +97,11 @@ void finiSections() nothrow @nogc
9597

9698
void[] initTLSRanges() nothrow @nogc
9799
{
98-
auto range = getTLSRange();
99-
assert(range.isValid, "Could not determine TLS range.");
100-
return range.toArray;
100+
static ubyte tlsAnchor;
101+
102+
auto range = getTLSRange(&tlsAnchor);
103+
safeAssert(range !is null, "Could not determine TLS range.");
104+
return range;
101105
}
102106

103107
void finiTLSRanges(void[] rng) nothrow @nogc
@@ -181,44 +185,19 @@ ubyte[] getSection(in mach_header* header, intptr_t slide,
181185

182186
extern (C) size_t malloc_size(const void* ptr) nothrow @nogc;
183187

184-
/// Represents a TLS range.
185-
struct TLSRange
186-
{
187-
/// The start of the range.
188-
void* start;
189-
190-
/// The size of the range.
191-
size_t size;
192-
193-
/// Returns `true` if the range is valid.
194-
bool isValid() const pure nothrow @nogc @safe
195-
{
196-
return start !is null && size > 0;
197-
}
198-
199-
/// Returns the range as an array.
200-
void[] toArray() pure nothrow @nogc
201-
{
202-
return start[0 .. size];
203-
}
204-
}
205-
206188
/// Returns the TLS range of the current image.
207-
TLSRange getTLSRange() nothrow @nogc
189+
void[] getTLSRange(const void* tlsSymbol) nothrow @nogc
208190
{
209-
static ubyte tlsAnchor;
210-
const tlsSymbol = &tlsAnchor;
211-
212191
foreach (i ; 0 .. _dyld_image_count)
213192
{
214193
const header = cast(const(mach_header_64)*) _dyld_get_image_header(i);
215194
auto tlvInfo = tlvInfo(header);
216195

217196
if (tlvInfo.foundTLSRange(tlsSymbol))
218-
return TLSRange(tlvInfo.tlv_addr, tlvInfo.tlv_size);
197+
return tlvInfo.tlv_addr[0 .. tlvInfo.tlv_size];
219198
}
220199

221-
return TLSRange.init;
200+
return null;
222201
}
223202

224203
/**
@@ -265,13 +244,13 @@ struct dyld_tlv_info
265244
*/
266245
dyld_tlv_info tlvInfo(const mach_header_64* header) nothrow @nogc
267246
{
268-
auto tlvAddress = pthread_getspecific(header.firstTLVKey);
269-
assert(tlvAddress, "No TLV address found");
247+
const key = header.firstTLVKey;
248+
auto tlvAddress = key == pthread_key_t.max ? null : pthread_getspecific(key);
270249

271250
dyld_tlv_info info = {
272251
info_size: dyld_tlv_info.sizeof,
273252
tlv_addr: tlvAddress,
274-
tlv_size: malloc_size(tlvAddress)
253+
tlv_size: tlvAddress ? malloc_size(tlvAddress) : 0
275254
};
276255

277256
return info;

src/rt/util/utility.d

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Contains various utility functions used by the runtime implementation.
3+
*
4+
* Copyright: Copyright Digital Mars 2016.
5+
* License: Distributed under the
6+
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7+
* (See accompanying file LICENSE)
8+
* Authors: Jacob Carlborg
9+
* Source: $(DRUNTIMESRC rt/util/_utility.d)
10+
*/
11+
module rt.util.utility;
12+
13+
/**
14+
* Asserts that the given condition is `true`.
15+
*
16+
* The assertion is independent from -release, by abort()ing. Regular assertions
17+
* throw an AssertError and thus require an initialized GC, which isn't the case
18+
* (yet or anymore) for the startup/shutdown code in this module
19+
* (called by CRT ctors/dtors etc.).
20+
*/
21+
package(rt) void safeAssert(
22+
bool condition, scope string msg, size_t line = __LINE__
23+
) nothrow @nogc @safe
24+
{
25+
import core.internal.abort;
26+
condition || abort(msg, __FILE__, line);
27+
}

0 commit comments

Comments
 (0)