Skip to content

Commit

Permalink
Switch: Fix dynamic link build on GCC 14 (mod loader)
Browse files Browse the repository at this point in the history
No idea if the feature even works, but it doesn't fail to build anymore.
Might remove later.
  • Loading branch information
Mefiresu committed Nov 9, 2024
1 parent 830071a commit ada5e98
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion dependencies/switch/libnx-dyn/address_space.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <address_space.h>
#include <string.h>
#include <stdlib.h>
#define RESULT_OK 0
#define ARRAY_LENGTH(a) sizeof((a))/sizeof((a)[0])

Expand Down Expand Up @@ -114,7 +116,7 @@ void *as_reserve(size_t len) {
continue;
}

if((r = svcQueryMemory(&memory_info, &page_info, (void*) addr)) != RESULT_OK) {
if((r = svcQueryMemory(&memory_info, &page_info, addr)) != RESULT_OK) {
goto fail_mutex;
}
} while(memory_info.type != 0 || memory_info.attr != 0 || memory_info.perm != 0 || (uint64_t) memory_info.addr + memory_info.size < addr + len);
Expand Down
14 changes: 7 additions & 7 deletions dependencies/switch/libnx-dyn/dyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static Result _dynLoad_elf(const char *path, DynModule *mod)

for (uint64_t i = 0; i < data->num_segments; i++) {
Dyn_Elf64_Seg *seg = &data->segments[i];
if (R_FAILED(res = svcMapProcessCodeMemory(ownHandle, seg->dst, seg->src, seg->size))) {
if (R_FAILED(res = svcMapProcessCodeMemory(ownHandle, (uint64_t)seg->dst, (uint64_t)seg->src, seg->size))) {
res = 0;
/*for (uint64_t j = 0; j < i; j++) {
svcUnmapProcessCodeMemory(ownHandle, seg->dst, seg->src, seg->size);
Expand Down Expand Up @@ -246,10 +246,10 @@ static Result _dynLoad_nrovsc(const char *path, DynModule *mod)
res = ldrRoLoadNro(&nro_addr, (u64)nro, filesz, (u64)bss, bss_sz);

if ((res == 0)) {
mod->input.nro = nro;
mod->input.nro = (void*)nro;
mod->input.nrr = nrr;
mod->input.bss = bss;
mod->input.base = nro_addr;
mod->input.base = (void*)nro_addr;
}
}
return res;
Expand All @@ -276,15 +276,15 @@ static Result _dynScan(DynModule *mod)
if (mod_header->magic != MOD0_MAGIC)
return MAKERESULT(Module_LibnxDyn, LibnxDynError_InvalidInputNro);

Result r = dynElfFindOffset(dynamic, DT_HASH, &mod->hash, module_base);
Result r = dynElfFindOffset(dynamic, DT_HASH, (void**)&mod->hash, module_base);
if ((r != 0) && (r != MAKERESULT(Module_LibnxDyn, LibnxDynError_MissingDtEntry)))
return r;

r = dynElfFindOffset(dynamic, DT_STRTAB, &mod->strtab, module_base);
r = dynElfFindOffset(dynamic, DT_STRTAB, (void**)&mod->strtab, module_base);
if ((r != 0) && (r != MAKERESULT(Module_LibnxDyn, LibnxDynError_MissingDtEntry)))
return r;

r = dynElfFindOffset(mod->dynamic, DT_SYMTAB, &mod->symtab, module_base);
r = dynElfFindOffset(mod->dynamic, DT_SYMTAB, (void**)&mod->symtab, module_base);
if ((r != 0) && (r != MAKERESULT(Module_LibnxDyn, LibnxDynError_MissingDtEntry)))
return r;

Expand Down Expand Up @@ -652,7 +652,7 @@ static Result _dynUnload(DynModule *mod)
Dyn_Elf64_Data *data = mod->input.loader_data;
for (uint64_t i = 0; i < data->num_segments; i++) {
Dyn_Elf64_Seg *seg = &data->segments[i];
svcUnmapProcessCodeMemory(ownHandle, seg->dst, seg->src, seg->size);
svcUnmapProcessCodeMemory(ownHandle, (uint64_t)seg->dst, (uint64_t)seg->src, seg->size);
if (seg->clone) {
free(seg->clone);
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies/switch/libnx-dyn/dynamic_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern void __real___nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn);
void __wrap___nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn) {

// Custom way to get base address to be used from modules later.
__nx_aslr_base = base;
__nx_aslr_base = (void*)base;

// Normal __nx_dynamic
__real___nx_dynamic(base, dyn);
Expand Down

0 comments on commit ada5e98

Please sign in to comment.