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

Commit 187510e

Browse files
authored
Merge pull request #3374 from MartinNowak/merge_stable
merge stable
2 parents a026ea4 + 277aa0b commit 187510e

File tree

6 files changed

+86
-13
lines changed

6 files changed

+86
-13
lines changed

mak/COPY

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ COPY=\
127127
$(IMPDIR)\core\sys\darwin\dlfcn.d \
128128
$(IMPDIR)\core\sys\darwin\err.d \
129129
$(IMPDIR)\core\sys\darwin\execinfo.d \
130+
$(IMPDIR)\core\sys\darwin\ifaddrs.d \
130131
$(IMPDIR)\core\sys\darwin\pthread.d \
131132
$(IMPDIR)\core\sys\darwin\stdlib.d \
132133
$(IMPDIR)\core\sys\darwin\string.d \

mak/SRCS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ SRCS=\
134134
src\core\sys\darwin\dlfcn.d \
135135
src\core\sys\darwin\err.d \
136136
src\core\sys\darwin\execinfo.d \
137+
src\core\sys\darwin\ifaddrs.d \
137138
src\core\sys\darwin\pthread.d \
138139
src\core\sys\darwin\stdlib.d \
139140
src\core\sys\darwin\string.d \
141+
\
140142
src\core\sys\darwin\mach\dyld.d \
141143
src\core\sys\darwin\mach\getsect.d \
142144
src\core\sys\darwin\mach\kern_return.d \
@@ -146,6 +148,7 @@ SRCS=\
146148
src\core\sys\darwin\mach\semaphore.d \
147149
src\core\sys\darwin\mach\stab.d \
148150
src\core\sys\darwin\mach\thread_act.d \
151+
\
149152
src\core\sys\darwin\netinet\in_.d \
150153
\
151154
src\core\sys\darwin\sys\cdefs.d \

src/core/atomic.d

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ T atomicFetchSub(MemoryOrder ms = MemoryOrder.seq, T)(ref T val, size_t mod) pur
196196
in (atomicValueIsProperlyAligned(val))
197197
{
198198
static if (is(T == U*, U))
199-
return cast(T)core.internal.atomic.atomicFetchAdd!ms(cast(size_t*)&val, mod * U.sizeof);
199+
return cast(T)core.internal.atomic.atomicFetchSub!ms(cast(size_t*)&val, mod * U.sizeof);
200200
else
201201
return core.internal.atomic.atomicFetchSub!ms(&val, cast(T)mod);
202202
}
@@ -1143,6 +1143,29 @@ version (CoreUnittest)
11431143
}
11441144
}
11451145

1146+
@betterC pure nothrow @nogc unittest
1147+
{
1148+
byte[10] byteArray = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
1149+
ulong[10] ulongArray = [2, 4, 6, 8, 10, 12, 14, 16, 19, 20];
1150+
1151+
{
1152+
auto array = byteArray;
1153+
byte* ptr = &array[0];
1154+
byte* prevPtr = atomicFetchAdd(ptr, 3);
1155+
assert(prevPtr == &array[0]);
1156+
assert(*prevPtr == 1);
1157+
assert(*ptr == 7);
1158+
}
1159+
{
1160+
auto array = ulongArray;
1161+
ulong* ptr = &array[0];
1162+
ulong* prevPtr = atomicFetchAdd(ptr, 3);
1163+
assert(prevPtr == &array[0]);
1164+
assert(*prevPtr == 2);
1165+
assert(*ptr == 8);
1166+
}
1167+
}
1168+
11461169
@betterC pure nothrow @nogc @safe unittest
11471170
{
11481171
shared ubyte u8 = 1;
@@ -1167,6 +1190,29 @@ version (CoreUnittest)
11671190
}
11681191
}
11691192

1193+
@betterC pure nothrow @nogc unittest
1194+
{
1195+
byte[10] byteArray = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
1196+
ulong[10] ulongArray = [2, 4, 6, 8, 10, 12, 14, 16, 19, 20];
1197+
1198+
{
1199+
auto array = byteArray;
1200+
byte* ptr = &array[5];
1201+
byte* prevPtr = atomicFetchSub(ptr, 4);
1202+
assert(prevPtr == &array[5]);
1203+
assert(*prevPtr == 11);
1204+
assert(*ptr == 3); // https://issues.dlang.org/show_bug.cgi?id=21578
1205+
}
1206+
{
1207+
auto array = ulongArray;
1208+
ulong* ptr = &array[5];
1209+
ulong* prevPtr = atomicFetchSub(ptr, 4);
1210+
assert(prevPtr == &array[5]);
1211+
assert(*prevPtr == 12);
1212+
assert(*ptr == 4); // https://issues.dlang.org/show_bug.cgi?id=21578
1213+
}
1214+
}
1215+
11701216
@betterC pure nothrow @nogc @safe unittest // issue 16651
11711217
{
11721218
shared ulong a = 2;

src/core/sys/posix/config.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ else version (CRuntime_UClibc)
117117
else version (CRuntime_Bionic)
118118
{
119119
enum _GNU_SOURCE = false;
120+
enum __USE_FILE_OFFSET64 = false; // see https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
120121
enum __USE_GNU = _GNU_SOURCE;
121122

122123
version (D_LP64)

src/core/sys/posix/dlfcn.d

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ else version (Darwin)
139139
char* dlerror();
140140
void* dlopen(const scope char*, int);
141141
void* dlsym(void*, const scope char*);
142-
int dladdr(void* addr, Dl_info* info);
142+
int dladdr(scope const void* addr, Dl_info* info);
143143

144144
struct Dl_info
145145
{
@@ -294,6 +294,15 @@ else version (CRuntime_Musl)
294294
const(char)* dlerror();
295295
void* dlopen(const scope char*, int);
296296
void* dlsym(void*, const scope char*);
297+
298+
int dladdr(scope const void *addr, Dl_info *info);
299+
struct Dl_info
300+
{
301+
const(char)* dli_fname;
302+
void* dli_fbase;
303+
const(char)* dli_sname;
304+
void* dli_saddr;
305+
}
297306
}
298307
else version (CRuntime_UClibc)
299308
{

src/rt/sections_elf_shared.d

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ else version (CRuntime_UClibc) enum SharedELF = true;
1919
else enum SharedELF = false;
2020
static if (SharedELF):
2121

22+
version (MIPS32) version = MIPS_Any;
23+
version (MIPS64) version = MIPS_Any;
24+
version (RISCV32) version = RISCV_Any;
25+
version (RISCV64) version = RISCV_Any;
26+
2227
// debug = PRINTF;
2328
import core.internal.elf.dl;
2429
import core.memory;
@@ -725,17 +730,29 @@ version (Shared)
725730
if (dyn.d_tag == DT_STRTAB)
726731
{
727732
version (CRuntime_Musl)
728-
strtab = cast(const(char)*)(object.baseAddress + dyn.d_un.d_ptr); // relocate
733+
enum relocate = true;
729734
else version (linux)
730-
strtab = cast(const(char)*)dyn.d_un.d_ptr;
735+
{
736+
// This might change in future glibc releases (after 2.29) as dynamic sections
737+
// are not required to be read-only on RISC-V. This was copy & pasted from MIPS
738+
// while upstreaming RISC-V support. Otherwise MIPS is the only arch which sets
739+
// in glibc: #define DL_RO_DYN_SECTION 1
740+
version (RISCV_Any) enum relocate = true;
741+
else version (MIPS_Any) enum relocate = true;
742+
else enum relocate = false;
743+
}
731744
else version (FreeBSD)
732-
strtab = cast(const(char)*)(object.baseAddress + dyn.d_un.d_ptr); // relocate
745+
enum relocate = true;
733746
else version (NetBSD)
734-
strtab = cast(const(char)*)(object.baseAddress + dyn.d_un.d_ptr); // relocate
747+
enum relocate = true;
735748
else version (DragonFlyBSD)
736-
strtab = cast(const(char)*)(object.baseAddress + dyn.d_un.d_ptr); // relocate
749+
enum relocate = true;
737750
else
738751
static assert(0, "unimplemented");
752+
753+
const base = relocate ? cast(const char*) object.baseAddress : null;
754+
strtab = base + dyn.d_un.d_ptr;
755+
739756
break;
740757
}
741758
}
@@ -875,9 +892,7 @@ else version (ARM)
875892
enum TLS_DTV_OFFSET = 0x0;
876893
else version (AArch64)
877894
enum TLS_DTV_OFFSET = 0x0;
878-
else version (RISCV32)
879-
enum TLS_DTV_OFFSET = 0x800;
880-
else version (RISCV64)
895+
else version (RISCV_Any)
881896
enum TLS_DTV_OFFSET = 0x800;
882897
else version (HPPA)
883898
enum TLS_DTV_OFFSET = 0x0;
@@ -889,9 +904,7 @@ else version (PPC)
889904
enum TLS_DTV_OFFSET = 0x8000;
890905
else version (PPC64)
891906
enum TLS_DTV_OFFSET = 0x8000;
892-
else version (MIPS32)
893-
enum TLS_DTV_OFFSET = 0x8000;
894-
else version (MIPS64)
907+
else version (MIPS_Any)
895908
enum TLS_DTV_OFFSET = 0x8000;
896909
else
897910
static assert( false, "Platform not supported." );

0 commit comments

Comments
 (0)