mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 04:11:18 +00:00
kern: simplify rela-in-bss impl
This commit is contained in:
parent
cfc54dbc88
commit
dc52da2819
3 changed files with 13 additions and 36 deletions
|
@ -9,23 +9,6 @@ def align_up(val, algn):
|
|||
val += algn - 1
|
||||
return val - (val % algn)
|
||||
|
||||
def find_rela(kernel, dynamic):
|
||||
rela_offset, rela_size = (None, None)
|
||||
while True:
|
||||
dyn_type, dyn_val = up('<QQ', kernel[dynamic:dynamic+0x10])
|
||||
if dyn_type == 0:
|
||||
break
|
||||
elif dyn_type == 7:
|
||||
assert (rela_offset is None)
|
||||
rela_offset = dyn_val
|
||||
elif dyn_type == 8:
|
||||
assert (rela_size is None)
|
||||
rela_size = dyn_val
|
||||
dynamic += 0x10
|
||||
assert (rela_offset is not None)
|
||||
assert (rela_size is not None)
|
||||
return (rela_offset, rela_size)
|
||||
|
||||
def main(argc, argv):
|
||||
if argc != 4:
|
||||
print('Usage: %s kernel_ldr.bin kernel.bin output.bin' % argv[0])
|
||||
|
@ -37,18 +20,14 @@ def main(argc, argv):
|
|||
kernel_metadata_offset = 4
|
||||
assert (kernel_metadata_offset <= len(kernel) - 0x40)
|
||||
assert (kernel[kernel_metadata_offset:kernel_metadata_offset + 4] == b'MSS0')
|
||||
bss_start, bss_end, kernel_end, dynamic = up('<IIII', kernel[kernel_metadata_offset + 0x30:kernel_metadata_offset + 0x40])
|
||||
|
||||
bss_start, bss_end, kernel_end = up('<III', kernel[kernel_metadata_offset + 0x30:kernel_metadata_offset + 0x3C])
|
||||
assert (bss_end >= bss_start)
|
||||
bss_size = bss_end - bss_start
|
||||
assert (bss_end == kernel_end)
|
||||
assert (kernel_end <= len(kernel))
|
||||
|
||||
rela_offset, rela_size = find_rela(kernel, dynamic)
|
||||
assert (rela_size == len(kernel) - kernel_end)
|
||||
assert (bss_start <= rela_offset and rela_offset + rela_size <= bss_end)
|
||||
assert (kernel[bss_start:bss_end] == (b'\x00'* bss_size))
|
||||
|
||||
kernel = kernel[:rela_offset] + kernel[bss_end:] + (b'\x00' * (bss_size - (rela_size + (rela_offset - bss_start))))
|
||||
assert (len(kernel) <= kernel_end)
|
||||
if len(kernel) < kernel_end:
|
||||
kernel += b'\x00' * (kernel_end - len(kernel))
|
||||
assert (kernel_end == len(kernel))
|
||||
|
||||
embedded_ini = b''
|
||||
|
|
|
@ -102,7 +102,7 @@ DEPENDS := $(OFILES:.o=.d)
|
|||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).bin : $(OUTPUT).elf
|
||||
$(OBJCOPY) -S -O binary --set-section-flags .bss=alloc,load,contents $< $@
|
||||
$(OBJCOPY) -S -O binary $< $@
|
||||
@echo built ... $(notdir $@)
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
|
|
@ -154,16 +154,14 @@ SECTIONS
|
|||
|
||||
__bss_start__ = .;
|
||||
|
||||
OVERLAY : NOCROSSREFS {
|
||||
.bss {
|
||||
.rela.dyn : { *(.rela.*) } :data
|
||||
|
||||
.bss ADDR(.rela.dyn) (NOLOAD) : {
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(0x1000);
|
||||
}
|
||||
.rela.dyn { *(.rela.*) }
|
||||
} :data
|
||||
|
||||
|
||||
__bss_end__ = .;
|
||||
|
||||
|
|
Loading…
Reference in a new issue