From c2c9f05328fe5199153b905223e4b7b1d60c433b Mon Sep 17 00:00:00 2001 From: James Benton Date: Sun, 27 Dec 2015 05:45:32 -0800 Subject: [PATCH] Proper PIE for RPL. --- rpl/common/rules.mk | 2 +- rpl/common/stub.S | 4 +-- rules/ppc.mk | 2 +- rules/rpl.ld | 71 +++++++++++++++++++++++++++++++++++++++++---- rules/rpl.mk | 2 +- 5 files changed, 70 insertions(+), 11 deletions(-) diff --git a/rpl/common/rules.mk b/rpl/common/rules.mk index badb996..e2f8fd5 100644 --- a/rpl/common/rules.mk +++ b/rpl/common/rules.mk @@ -15,7 +15,7 @@ endif include $(WUT_ROOT)/rules/ppc.mk LD := $(PREFIX)ld -RPLCFLAGS := -Wno-unused-variable -fPIC -fpic -fno-builtin +RPLCFLAGS := -Wno-unused-variable -fno-builtin CFLAGS += -O2 -Wall -std=c11 $(RPLCFLAGS) ODEPS := stub.o lib.o diff --git a/rpl/common/stub.S b/rpl/common/stub.S index 7d0e4b4..5ac8215 100644 --- a/rpl/common/stub.S +++ b/rpl/common/stub.S @@ -5,8 +5,8 @@ .section ".rplTramp.text","ax"; \ .global name; \ name: \ - li %r0, 0; \ - oris %r0, %r0, 0; \ + li %r0, name##_stub@l; \ + oris %r0, %r0, name##_stub@ha; \ mtctr %r0; \ bctr; \ diff --git a/rules/ppc.mk b/rules/ppc.mk index 91f2809..4bbd228 100644 --- a/rules/ppc.mk +++ b/rules/ppc.mk @@ -1,7 +1,7 @@ LIBPATHS := -L$(WUT_ROOT)/lib CFLAGS := -I$(WUT_ROOT)/include -fno-builtin -ffreestanding CXXFLAGS := $(CFLAGS) -LDFLAGS := -nostdlib -nostartfiles -T $(WUT_ROOT)/rules/rpl.ld +LDFLAGS := -nostdlib -nostartfiles include $(WUT_ROOT)/rules/base.mk diff --git a/rules/rpl.ld b/rules/rpl.ld index 7094cab..3aa7ae3 100644 --- a/rules/rpl.ld +++ b/rules/rpl.ld @@ -4,19 +4,24 @@ OUTPUT_ARCH(powerpc:common) ENTRY(_start) MEMORY { - system (rw) : ORIGIN = 0x01000000, LENGTH = 32M + system (rwx) : ORIGIN = 0x01000000, LENGTH = 32M code (rwx) : ORIGIN = 0x02000000, LENGTH = 224M data (rw) : ORIGIN = 0x10000000, LENGTH = 800M + load (rwx) : ORIGIN = 0xC0000000, LENGTH = 128M } PHDRS { + hdr_text PT_LOAD FILEHDR PHDRS FLAGS(0x01 | 0x04); + hdr_data PT_LOAD FLAGS(0x02 | 0x04); + hdr_srodata PT_LOAD FLAGS(0x04); + hdr_sdata PT_LOAD FLAGS(0x02 | 0x04); } SECTIONS { . = ORIGIN(code); /* Standard code section */ - .text ALIGN(32) : { *(.text .stub .text.*) } + .text ALIGN(32) : { *(.text .stub .text.*) } : hdr_text /* * Trampolines for each RPL function, have the same symbol name of @@ -42,7 +47,7 @@ SECTIONS { /* * Contains the name of RPLs, referenced by .lib.rplLibs */ - .rodata.rplNames ALIGN(32) : { KEEP (*(.rodata.rplNames)) } + .rodata.rplNames ALIGN(32) : { KEEP (*(.rodata.rplNames)) } : hdr_data /* * List of RPL libraries to import, in format: @@ -57,10 +62,64 @@ SECTIONS { */ .data.rplFuncStubs ALIGN(32) : { KEEP (*(.data.rplFuncStubs)) } + .interp ALIGN(32) : { *(.interp) } + .hash ALIGN(32) : { *(.hash) } + .dynsym ALIGN(32) : { *(.dynsym) } + .dynstr ALIGN(32) : { *(.dynstr) } + .rela.dyn ALIGN(32) : { *(.rela.dyn) } + .rela.text ALIGN(32) : { *(.rela.text) } + .eh_frame ALIGN(32) : { *(.eh_frame) } + .dynamic ALIGN(32) : { *(.dynamic) } + .got ALIGN(32) : { *(.got) } + .comment ALIGN(32) : { *(.comment) } + .shstrtab ALIGN(32) : { *(.shstrtab) } + .symtab ALIGN(32) : { *(.symtab) } + .strtab ALIGN(32) : { *(.strtab) } + + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*) + *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*) + *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*) + *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + } + + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.toc) + *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) + *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*) + *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) + *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + } + /* Standard data sections */ . = ORIGIN(data); - .rodata ALIGN(256) : { *(.rodata .rodata.*) } - .data ALIGN(256) : { *(.data) } - .bss ALIGN(256) : { *(.bss) } + .rodata ALIGN(256) : { *(.rodata .rodata.*) } : hdr_srodata + .data ALIGN(256) : { *(.data) } : hdr_sdata + .bss ALIGN(256) : { *(.sbss) *(.bss) } } diff --git a/rules/rpl.mk b/rules/rpl.mk index 08a3f8d..73148d5 100644 --- a/rules/rpl.mk +++ b/rules/rpl.mk @@ -1,7 +1,7 @@ LIBPATHS := -L$(WUT_ROOT)/lib CFLAGS := -I$(WUT_ROOT)/include -fno-builtin -ffreestanding CXXFLAGS := $(CFLAGS) -LDFLAGS := -nostdlib -nostartfiles $(WUT_ROOT)/lib/crt0.o -T $(WUT_ROOT)/rules/rpl.ld +LDFLAGS := -nostdlib -nostartfiles $(WUT_ROOT)/lib/crt0.o -T $(WUT_ROOT)/rules/rpl.ld -pie -fPIE include $(WUT_ROOT)/rules/base.mk