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

Commit 356b5f0

Browse files
kinkeGeod24
authored andcommitted
rt.sections_elf_shared: Upstream MIPS/RISC-V fix wrt. .so dependency names from GDC
1 parent 2d1f8ef commit 356b5f0

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

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)