Skip to content

Commit

Permalink
Fix linking and PIE -> PIC
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowninja108 committed Jan 9, 2020
1 parent 6a1bda8 commit 30cdf23
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 48 deletions.
5 changes: 3 additions & 2 deletions MakefileNSO
Expand Up @@ -39,14 +39,15 @@ SOURCES := source \
source/skyline/nx/runtime \
source/skyline/nx/sf \
source/skyline/inlinehook \
source/skyline/logger
source/skyline/logger \
source/skyline/plugin
DATA := data
INCLUDES := include

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -ftls-model=local-exec
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec

CFLAGS := -g -Wall -ffunction-sections \
$(ARCH) $(DEFINES)
Expand Down
30 changes: 15 additions & 15 deletions include/operator.h
Expand Up @@ -6,23 +6,23 @@
#pragma once

#include <cstddef>
#include <std.h>
#include <new>
#include "types.h"

// Nintendo didn't implement these for some reason
void* WEAK operator new(std::size_t size, void*);
void* WEAK operator new[](std::size_t size, void*);
void* operator new(std::size_t size, void*);
void* operator new[](std::size_t size, void*);

void* WEAK operator new(std::size_t size);
void* WEAK operator new[](std::size_t size);
void* WEAK operator new(std::size_t size, std::nothrow_t const &);
void* WEAK operator new[](std::size_t size, std::nothrow_t const &);
void* WEAK operator new(std::size_t size, ulong);
void* WEAK operator new[](std::size_t size, ulong);
void* operator new(std::size_t size);
void* operator new[](std::size_t size);
void* operator new(std::size_t size, std::nothrow_t const &);
void* operator new[](std::size_t size, std::nothrow_t const &);
void* operator new(std::size_t size, ulong);
void* operator new[](std::size_t size, ulong);

void WEAK operator delete(void *);
void WEAK operator delete(void *, std::size_t);
void WEAK operator delete(void *, std::nothrow_t const &);
void WEAK operator delete[](void *);
void WEAK operator delete[](void *, std::size_t);
void WEAK operator delete[](void *, std::nothrow_t const &);
void operator delete(void *);
void operator delete(void *, std::size_t);
void operator delete(void *, std::nothrow_t const &);
void operator delete[](void *);
void operator delete[](void *, std::size_t);
void operator delete[](void *, std::nothrow_t const &);
38 changes: 37 additions & 1 deletion include/std.h
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include "types.h"
#include "operator.h"
#include <string>

namespace std
{
Expand Down Expand Up @@ -58,5 +60,39 @@ namespace std

template<typename T, typename T2>
void __insertion_sort_incomplete(T2, T2, T);
};
};

namespace __1 {
class locale {
class facet {
~facet();
void __on_zero_shared();
};

class id {
void __init();
void __get();
};

public:
static locale global(locale const&);
static locale __global();
static const locale& classic();

locale();
locale(locale const&);
locale(locale const&, locale const&, int);
locale(locale const&, std::string const&, int);
locale(std::string const&);

std::string name() const;

bool has_facet(locale::id const&);

int operator=(locale const&);
void operator==(locale const&);

~locale();
};
};
};
60 changes: 31 additions & 29 deletions linkerscripts/application.ld
@@ -1,9 +1,8 @@
OUTPUT_FORMAT(elf64-littleaarch64)
OUTPUT_ARCH(aarch64)
ENTRY(__module_start)

PHDRS
{
{
text PT_LOAD FLAGS(5);
rodata PT_LOAD FLAGS(4);
data PT_LOAD FLAGS(6);
Expand All @@ -26,13 +25,13 @@ SECTIONS

/* Trampoline and stuffs */
.plt : { *(.plt .plt.*) } :text
__code_end__ = .;

/* Read-only sections */
. = ALIGN(0x1000);
__rodata_start = . ;

/* App name */
.application_name : { KEEP (*(.rodata.application_name)) } :rodata
.module_name : { KEEP (*(.rodata.module_name)) } :rodata

/* Make sure everything is aligned */
. = ALIGN(8);
Expand All @@ -48,38 +47,28 @@ SECTIONS
.dynsym : { *(.dynsym .dynsym.*) } :rodata
.dynstr : { *(.dynstr .dynstr.*) } :rodata

/* All relocations sections */
.rel.init : { *(.rel.init) } :rodata
.rela.init : { *(.rela.init) } :rodata
.rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } :rodata
.rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } :rodata
.rel.fini : { *(.rel.fini) } :rodata
.rela.fini : { *(.rela.fini) } :rodata
.rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } :rodata
.rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } :rodata
.rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } :rodata
.rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } :rodata
.rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } :rodata
.rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } :rodata
.rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } :rodata
.rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } :rodata
.rel.ctors : { *(.rel.ctors) } :rodata
.rela.ctors : { *(.rela.ctors) } :rodata
.rel.dtors : { *(.rel.dtors) } :rodata
.rela.dtors : { *(.rela.dtors) } :rodata
.rel.got : { *(.rel.got) } :rodata
.rela.got : { *(.rela.got) } :rodata
.rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } :rodata
.rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } :rodata
__rel_dyn_start__ = .;
.rel.dyn : { *(.rel.dyn) } :rodata
__rel_dyn_end__ = .;

__rela_dyn_start__ = .;
.rela.dyn : { *(.rela.dyn) } :rodata
__rela_dyn_end__ = .;

__rel_plt_start__ = .;
.rel.plt : { *(.rel.plt) } :rodata
__rel_plt_end__ = .;

__rela_plt_start__ = .;
.rela.plt : { *(.rela.plt) } :rodata
__rela_plt_end__ = .;

/* All exception handling sections */
.gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } :rodata
.eh_frame_hdr : {
__eh_frame_hdr_start__ = .;
HIDDEN(__eh_frame_hdr_start__ = .);
*(.eh_frame_hdr)
__eh_frame_hdr_end__ = .;
HIDDEN(__eh_frame_hdr_end__ = .);
} :rodata
.eh_frame : { KEEP (*(.eh_frame)) } :rodata

Expand Down Expand Up @@ -107,7 +96,9 @@ SECTIONS
} :data

/* All GOT sections */
__got_start__ = .;
.got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } :data
__got_end__ = .;

/* The dynamic section as we need it to be stored in the binary */
.dynamic : {
Expand All @@ -118,16 +109,27 @@ SECTIONS
/* Align for .init_array/.fini_array */
. = ALIGN(8);

.preinit_array ALIGN(8) :
{
PROVIDE (__preinit_array_start__ = .);
KEEP (*(.preinit_array))
PROVIDE (__preinit_array_end__ = .);
} :data

/* App init array */
.init_array : {
PROVIDE (__init_array_start__ = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
KEEP (*(.init_array))
PROVIDE (__init_array_end__ = .);
} :data

/* App fini array */
.fini_array : {
PROVIDE (__fini_array_start__ = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))
KEEP (*(.fini_array))
PROVIDE (__fini_array_end__ = .);
} :data

/* Thread Local sections */
Expand Down
2 changes: 1 addition & 1 deletion switch.specs
@@ -1,7 +1,7 @@
%rename link old_link

*link:
%(old_link) -T ../linkerscripts/application.ld ../linkerscripts/symstemp.ld --shared --gc-sections --build-id=sha1 --build-id=sha1
%(old_link) -T ../linkerscripts/application.ld ../linkerscripts/symstemp.ld --shared --gc-sections --build-id=sha1

*startfile:
crti%O%s crtbegin%O%s

0 comments on commit 30cdf23

Please sign in to comment.