mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-23 23:31:11 +01:00
kern: simplify rela-in-bss impl
This commit is contained in:
parent
cfc54dbc88
commit
dc52da2819
@ -9,23 +9,6 @@ def align_up(val, algn):
|
|||||||
val += algn - 1
|
val += algn - 1
|
||||||
return val - (val % algn)
|
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):
|
def main(argc, argv):
|
||||||
if argc != 4:
|
if argc != 4:
|
||||||
print('Usage: %s kernel_ldr.bin kernel.bin output.bin' % argv[0])
|
print('Usage: %s kernel_ldr.bin kernel.bin output.bin' % argv[0])
|
||||||
@ -37,18 +20,14 @@ def main(argc, argv):
|
|||||||
kernel_metadata_offset = 4
|
kernel_metadata_offset = 4
|
||||||
assert (kernel_metadata_offset <= len(kernel) - 0x40)
|
assert (kernel_metadata_offset <= len(kernel) - 0x40)
|
||||||
assert (kernel[kernel_metadata_offset:kernel_metadata_offset + 4] == b'MSS0')
|
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)
|
assert (bss_end >= bss_start)
|
||||||
bss_size = bss_end - bss_start
|
|
||||||
assert (bss_end == kernel_end)
|
assert (bss_end == kernel_end)
|
||||||
assert (kernel_end <= len(kernel))
|
|
||||||
|
|
||||||
rela_offset, rela_size = find_rela(kernel, dynamic)
|
assert (len(kernel) <= kernel_end)
|
||||||
assert (rela_size == len(kernel) - kernel_end)
|
if len(kernel) < kernel_end:
|
||||||
assert (bss_start <= rela_offset and rela_offset + rela_size <= bss_end)
|
kernel += b'\x00' * (kernel_end - len(kernel))
|
||||||
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 (kernel_end == len(kernel))
|
assert (kernel_end == len(kernel))
|
||||||
|
|
||||||
embedded_ini = b''
|
embedded_ini = b''
|
||||||
|
@ -102,7 +102,7 @@ DEPENDS := $(OFILES:.o=.d)
|
|||||||
# main targets
|
# main targets
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
$(OUTPUT).bin : $(OUTPUT).elf
|
$(OUTPUT).bin : $(OUTPUT).elf
|
||||||
$(OBJCOPY) -S -O binary --set-section-flags .bss=alloc,load,contents $< $@
|
$(OBJCOPY) -S -O binary $< $@
|
||||||
@echo built ... $(notdir $@)
|
@echo built ... $(notdir $@)
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
$(OUTPUT).elf : $(OFILES)
|
||||||
|
@ -154,16 +154,14 @@ SECTIONS
|
|||||||
|
|
||||||
__bss_start__ = .;
|
__bss_start__ = .;
|
||||||
|
|
||||||
OVERLAY : NOCROSSREFS {
|
.rela.dyn : { *(.rela.*) } :data
|
||||||
.bss {
|
|
||||||
*(.dynbss)
|
|
||||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
|
||||||
*(COMMON)
|
|
||||||
. = ALIGN(0x1000);
|
|
||||||
}
|
|
||||||
.rela.dyn { *(.rela.*) }
|
|
||||||
} :data
|
|
||||||
|
|
||||||
|
.bss ADDR(.rela.dyn) (NOLOAD) : {
|
||||||
|
*(.dynbss)
|
||||||
|
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||||
|
*(COMMON)
|
||||||
|
. = ALIGN(0x1000);
|
||||||
|
}
|
||||||
|
|
||||||
__bss_end__ = .;
|
__bss_end__ = .;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user