[build] Warn on zero-length symbols when building symbol table
Make build_symbol_table.py output statistics on the symbol table it builds, and emit warnings for zero-length symbols. Also added lengths to several functions defined in asm that this uncovered.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
import re
|
||||
|
||||
sym_re = re.compile(r'([0-9a-fA-F]{16}) ([0-9a-fA-F]{16}) [tTvVwW] (.*)')
|
||||
sym_re = re.compile(r'([0-9a-fA-F]{16}) ([0-9a-fA-F]{16} )?[tTvVwW] (.*)')
|
||||
|
||||
def parse_syms(infile):
|
||||
"""Take the output of the `nm` command, and parse it into a tuple
|
||||
@@ -30,8 +30,14 @@ def parse_syms(infile):
|
||||
if not match: continue
|
||||
|
||||
addr = int(match.group(1), base=16)
|
||||
size = int(match.group(2), base=16)
|
||||
size = int(match.group(2) or "0", base=16)
|
||||
name = match.group(3)
|
||||
|
||||
if size == 0:
|
||||
if not "." in name:
|
||||
print(f"SYMBOL WARNING: zero size for symbol {name}")
|
||||
continue
|
||||
|
||||
syms.append([addr, size, name, 0])
|
||||
|
||||
return syms
|
||||
@@ -61,6 +67,8 @@ def write_table(syms, outfile):
|
||||
pos = s[3]
|
||||
outfile.write(struct.pack("@QQQ", addr, size, pos))
|
||||
|
||||
return len(syms)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
@@ -68,5 +76,11 @@ if __name__ == "__main__":
|
||||
print(f"Usage: nm -n -S --demangle | {sys.argv[0]} <output>")
|
||||
sys.exit(1)
|
||||
|
||||
outfile = open(sys.argv[1], "wb")
|
||||
write_table(parse_syms(sys.stdin), outfile)
|
||||
syms = 0
|
||||
size = 0
|
||||
with open(sys.argv[1], "wb") as outfile:
|
||||
syms = write_table(parse_syms(sys.stdin), outfile)
|
||||
outfile.seek(0, 2)
|
||||
size = outfile.tell()
|
||||
|
||||
print(f"Wrote {syms} symbols ({size/1024:.1f} KiB) to {sys.argv[1]}.")
|
||||
|
||||
@@ -42,15 +42,17 @@ bsp_idle:
|
||||
jmp bsp_idle
|
||||
.end:
|
||||
|
||||
global interrupts_enable: function hidden
|
||||
global interrupts_enable: function hidden (interrupts_enable.end - interrupts_enable)
|
||||
interrupts_enable:
|
||||
sti
|
||||
ret
|
||||
.end:
|
||||
|
||||
global interrupts_disable: function hidden
|
||||
global interrupts_disable: function hidden (interrupts_disable.end - interrupts_disable)
|
||||
interrupts_disable:
|
||||
cli
|
||||
ret
|
||||
.end:
|
||||
|
||||
section .bss
|
||||
align 0x100
|
||||
|
||||
@@ -1,33 +1,39 @@
|
||||
global get_rsp: function hidden
|
||||
global get_rsp: function hidden (get_rsp.end - get_rsp)
|
||||
get_rsp:
|
||||
mov rax, rsp
|
||||
ret
|
||||
.end:
|
||||
|
||||
global get_rip: function hidden
|
||||
global get_rip: function hidden (get_rip.end - get_rip)
|
||||
get_rip:
|
||||
pop rax ; do the same thing as 'ret', except with 'jmp'
|
||||
jmp rax ; with the return address still in rax
|
||||
.end:
|
||||
|
||||
global get_caller: function hidden
|
||||
global get_caller: function hidden (get_caller.end - get_caller)
|
||||
get_caller:
|
||||
; No prelude - don't touch rsp or rbp
|
||||
mov rax, [rbp+8]
|
||||
ret
|
||||
.end:
|
||||
|
||||
global get_grandcaller: function hidden
|
||||
global get_grandcaller: function hidden (get_grandcaller.end - get_grandcaller)
|
||||
get_grandcaller:
|
||||
; No prelude - don't touch rsp or rbp
|
||||
mov rax, [rbp]
|
||||
mov rax, [rax+8]
|
||||
ret
|
||||
.end:
|
||||
|
||||
global get_gsbase: function hidden
|
||||
global get_gsbase: function hidden (get_gsbase.end - get_gsbase)
|
||||
get_gsbase:
|
||||
rdgsbase rax
|
||||
ret
|
||||
.end:
|
||||
|
||||
global _halt: function hidden
|
||||
global _halt: function hidden (_halt.end - _halt)
|
||||
_halt:
|
||||
hlt
|
||||
jmp _halt
|
||||
.end:
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
|
||||
global idt_write: function hidden
|
||||
global idt_write: function hidden (idt_write.end - idt_write)
|
||||
idt_write:
|
||||
lidt [rdi] ; first arg is the IDT pointer location
|
||||
ret
|
||||
.end:
|
||||
|
||||
global idt_load: function hidden
|
||||
global idt_load: function hidden (idt_load.end - idt_load)
|
||||
idt_load:
|
||||
sidt [rdi] ; first arg is where to write the idtr value
|
||||
ret
|
||||
.end:
|
||||
|
||||
global gdt_write: function hidden
|
||||
global gdt_write: function hidden (gdt_write.end - gdt_write)
|
||||
gdt_write:
|
||||
lgdt [rdi] ; first arg is the GDT pointer location
|
||||
|
||||
@@ -27,9 +29,11 @@ gdt_write:
|
||||
.next:
|
||||
ltr cx ; fourth arg is the TSS
|
||||
ret
|
||||
.end:
|
||||
|
||||
global gdt_load: function hidden
|
||||
global gdt_load: function hidden (gdt_load.end - gdt_load)
|
||||
gdt_load:
|
||||
sgdt [rdi] ; first arg is where to write the gdtr value
|
||||
ret
|
||||
.end:
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ bits 16
|
||||
default rel
|
||||
align 8
|
||||
|
||||
global ap_startup: function hidden
|
||||
global ap_startup: function hidden (ap_startup.end - ap_startup)
|
||||
ap_startup:
|
||||
jmp .start_real
|
||||
|
||||
@@ -102,15 +102,16 @@ align 8
|
||||
|
||||
mov rax, [BASE + (.ret - ap_startup)]
|
||||
jmp rax
|
||||
.end:
|
||||
|
||||
|
||||
global ap_startup_code_size: function hidden
|
||||
global ap_startup_code_size: data hidden
|
||||
ap_startup_code_size:
|
||||
dq ($ - ap_startup)
|
||||
|
||||
|
||||
section .text
|
||||
global init_ap_trampoline: function hidden
|
||||
global init_ap_trampoline: function hidden (init_ap_trampoline.end - init_ap_trampoline)
|
||||
init_ap_trampoline:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
@@ -129,6 +130,7 @@ init_ap_trampoline:
|
||||
|
||||
pop rbp
|
||||
ret
|
||||
.end:
|
||||
|
||||
extern long_ap_startup
|
||||
global ap_idle:function hidden (ap_idle.end - ap_idle)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%include "tasking.inc"
|
||||
|
||||
global task_switch: function hidden
|
||||
global task_switch: function hidden (task_switch.end - task_switch)
|
||||
task_switch:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
@@ -60,8 +60,10 @@ task_switch:
|
||||
|
||||
pop rbp
|
||||
ret
|
||||
.end:
|
||||
|
||||
global _current_gsbase: function hidden
|
||||
global _current_gsbase: function hidden (_current_gsbase.end - _current_gsbase)
|
||||
_current_gsbase:
|
||||
mov rax, [gs:CPU_DATA.self]
|
||||
ret
|
||||
.end:
|
||||
|
||||
Reference in New Issue
Block a user