misc: Split off a stage 2 symbol map and embed it into stage 2 so that it can print stacktrace symbol names before stage 3 is loaded
This commit is contained in:
parent
6d9d3259a1
commit
9e60b1da10
@ -74,7 +74,8 @@ ifeq ($(TARGET), bios)
|
||||
-static \
|
||||
-fno-pie \
|
||||
-lgcc \
|
||||
-static-libgcc
|
||||
-static-libgcc \
|
||||
-Wl,--gc-sections
|
||||
endif
|
||||
|
||||
.PHONY: all clean builddir
|
||||
@ -121,24 +122,31 @@ $(BUILDDIR)/stage2.bin.gz: $(BUILDDIR)/stage2.bin
|
||||
$(BUILDDIR)/stage2.bin: $(BUILDDIR)/limine.sys
|
||||
dd if=$< bs=$$(( 0x$$($(READELF) -S $(BUILDDIR)/limine.elf | grep .stage3.text | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
||||
|
||||
$(BUILDDIR)/limine.map.o: $(BUILDDIR)/limine_nomap.elf
|
||||
$(BUILDDIR)/stage2.map.o: $(BUILDDIR)/limine_stage2only.elf
|
||||
GENSYMS="`pwd`/gensyms.sh" && \
|
||||
cd "`dirname $<`" && \
|
||||
"$$GENSYMS" $(OBJDUMP) $< limine
|
||||
"$$GENSYMS" $(OBJDUMP) $< stage2
|
||||
|
||||
$(BUILDDIR)/full.map.o: $(BUILDDIR)/limine_nomap.elf
|
||||
GENSYMS="`pwd`/gensyms.sh" && \
|
||||
cd "`dirname $<`" && \
|
||||
"$$GENSYMS" $(OBJDUMP) $< full
|
||||
|
||||
$(BUILDDIR)/limine.sys: $(BUILDDIR)/limine.elf
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
$(BUILDDIR)/limine_nomap.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
|
||||
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
|
||||
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Wl,--gc-sections -Tlinker_stage2only.ld -o $(BUILDDIR)/limine_stage2only.elf || \
|
||||
$(BUILDDIR)/limine_stage2only.elf: $(OBJ)
|
||||
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_stage2only.ld -o $@ || \
|
||||
( echo "This error means that stage 2 was trying to use stage 3 symbols before loading stage 3" && \
|
||||
false )
|
||||
|
||||
$(BUILDDIR)/limine.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/limine.map.o
|
||||
$(BUILDDIR)/limine_nomap.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/stage2.map.o
|
||||
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
|
||||
|
||||
$(BUILDDIR)/limine.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/stage2.map.o $(BUILDDIR)/full.map.o
|
||||
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
|
||||
|
||||
$(BUILDDIR)/limine_dbg.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
|
||||
$(BUILDDIR)/limine_dbg.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/stage2.map.o $(BUILDDIR)/full.map.o
|
||||
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_dbg.ld -o $@
|
||||
|
||||
endif
|
||||
|
@ -11,7 +11,7 @@ $1 -t "$2" | sed '/\bd\b/d' | sort > "$TMP1"
|
||||
grep "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
|
||||
grep "\.text" < "$TMP1" | awk 'NF{ print $NF }' > "$TMP3"
|
||||
|
||||
echo "section .map" > "$TMP4"
|
||||
echo "section .$3_map" > "$TMP4"
|
||||
echo "global $3_map" >> "$TMP4"
|
||||
echo "$3_map:" >> "$TMP4"
|
||||
|
||||
|
@ -8,12 +8,16 @@
|
||||
#include <fs/file.h>
|
||||
#include <mm/pmm.h>
|
||||
|
||||
extern symbol limine_map;
|
||||
extern symbol stage2_map, full_map;
|
||||
|
||||
char *trace_address(size_t *off, size_t addr) {
|
||||
char *limine_map;
|
||||
|
||||
#if defined (bios)
|
||||
if (!stage3_loaded)
|
||||
return NULL;
|
||||
limine_map = stage2_map;
|
||||
else
|
||||
limine_map = full_map;
|
||||
#endif
|
||||
|
||||
uintptr_t prev_addr = 0;
|
||||
|
@ -23,6 +23,7 @@ SECTIONS
|
||||
*.s2.o(.rodata*)
|
||||
*libgcc.a:*(.data*)
|
||||
*libgcc.a:*(.rodata*)
|
||||
*(.stage2_map)
|
||||
}
|
||||
|
||||
.stage3.text : {
|
||||
@ -35,10 +36,7 @@ SECTIONS
|
||||
.stage3.data : {
|
||||
*(.data*)
|
||||
*(.rodata*)
|
||||
}
|
||||
|
||||
.map : {
|
||||
*(.map*)
|
||||
*(.full_map*)
|
||||
limine_sys_size = . - 0x8000;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ SECTIONS
|
||||
*.s2.o(.rodata*)
|
||||
*libgcc.a:*(.data*)
|
||||
*libgcc.a:*(.rodata*)
|
||||
*(.stage2_map)
|
||||
}
|
||||
|
||||
.stage3.text : {
|
||||
@ -35,11 +36,8 @@ SECTIONS
|
||||
.stage3.data : {
|
||||
*(.data*)
|
||||
*(.rodata*)
|
||||
}
|
||||
|
||||
.map : {
|
||||
limine_map = .;
|
||||
limine_sys_size = .;
|
||||
*(.full_map*)
|
||||
limine_sys_size = . - 0x8000;
|
||||
}
|
||||
|
||||
.bss : {
|
||||
|
@ -23,6 +23,7 @@ SECTIONS
|
||||
*.s2.o(.rodata*)
|
||||
*libgcc.a:*(.data*)
|
||||
*libgcc.a:*(.rodata*)
|
||||
*(.stage2_map)
|
||||
}
|
||||
|
||||
.stage3.text : {
|
||||
@ -35,11 +36,8 @@ SECTIONS
|
||||
.stage3.data : {
|
||||
*(.data*)
|
||||
*(.rodata*)
|
||||
}
|
||||
|
||||
.map : {
|
||||
limine_map = .;
|
||||
limine_sys_size = .;
|
||||
full_map = .;
|
||||
limine_sys_size = . - 0x8000;
|
||||
}
|
||||
|
||||
.bss : {
|
||||
|
@ -23,9 +23,10 @@ SECTIONS
|
||||
*.s2.o(.rodata*)
|
||||
*libgcc.a:*(.data*)
|
||||
*libgcc.a:*(.rodata*)
|
||||
stage2_map = .;
|
||||
stage3_addr = .;
|
||||
*(.stage3_build_id*)
|
||||
limine_map = .;
|
||||
full_map = .;
|
||||
limine_sys_size = .;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user