mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[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
|
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):
|
def parse_syms(infile):
|
||||||
"""Take the output of the `nm` command, and parse it into a tuple
|
"""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
|
if not match: continue
|
||||||
|
|
||||||
addr = int(match.group(1), base=16)
|
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)
|
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])
|
syms.append([addr, size, name, 0])
|
||||||
|
|
||||||
return syms
|
return syms
|
||||||
@@ -61,6 +67,8 @@ def write_table(syms, outfile):
|
|||||||
pos = s[3]
|
pos = s[3]
|
||||||
outfile.write(struct.pack("@QQQ", addr, size, pos))
|
outfile.write(struct.pack("@QQQ", addr, size, pos))
|
||||||
|
|
||||||
|
return len(syms)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
@@ -68,5 +76,11 @@ if __name__ == "__main__":
|
|||||||
print(f"Usage: nm -n -S --demangle | {sys.argv[0]} <output>")
|
print(f"Usage: nm -n -S --demangle | {sys.argv[0]} <output>")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
outfile = open(sys.argv[1], "wb")
|
syms = 0
|
||||||
write_table(parse_syms(sys.stdin), outfile)
|
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
|
jmp bsp_idle
|
||||||
.end:
|
.end:
|
||||||
|
|
||||||
global interrupts_enable: function hidden
|
global interrupts_enable: function hidden (interrupts_enable.end - interrupts_enable)
|
||||||
interrupts_enable:
|
interrupts_enable:
|
||||||
sti
|
sti
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global interrupts_disable: function hidden
|
global interrupts_disable: function hidden (interrupts_disable.end - interrupts_disable)
|
||||||
interrupts_disable:
|
interrupts_disable:
|
||||||
cli
|
cli
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
align 0x100
|
align 0x100
|
||||||
|
|||||||
@@ -1,33 +1,39 @@
|
|||||||
global get_rsp: function hidden
|
global get_rsp: function hidden (get_rsp.end - get_rsp)
|
||||||
get_rsp:
|
get_rsp:
|
||||||
mov rax, rsp
|
mov rax, rsp
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global get_rip: function hidden
|
global get_rip: function hidden (get_rip.end - get_rip)
|
||||||
get_rip:
|
get_rip:
|
||||||
pop rax ; do the same thing as 'ret', except with 'jmp'
|
pop rax ; do the same thing as 'ret', except with 'jmp'
|
||||||
jmp rax ; with the return address still in rax
|
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:
|
get_caller:
|
||||||
; No prelude - don't touch rsp or rbp
|
; No prelude - don't touch rsp or rbp
|
||||||
mov rax, [rbp+8]
|
mov rax, [rbp+8]
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global get_grandcaller: function hidden
|
global get_grandcaller: function hidden (get_grandcaller.end - get_grandcaller)
|
||||||
get_grandcaller:
|
get_grandcaller:
|
||||||
; No prelude - don't touch rsp or rbp
|
; No prelude - don't touch rsp or rbp
|
||||||
mov rax, [rbp]
|
mov rax, [rbp]
|
||||||
mov rax, [rax+8]
|
mov rax, [rax+8]
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global get_gsbase: function hidden
|
global get_gsbase: function hidden (get_gsbase.end - get_gsbase)
|
||||||
get_gsbase:
|
get_gsbase:
|
||||||
rdgsbase rax
|
rdgsbase rax
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global _halt: function hidden
|
global _halt: function hidden (_halt.end - _halt)
|
||||||
_halt:
|
_halt:
|
||||||
hlt
|
hlt
|
||||||
jmp _halt
|
jmp _halt
|
||||||
|
.end:
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
|
|
||||||
global idt_write: function hidden
|
global idt_write: function hidden (idt_write.end - idt_write)
|
||||||
idt_write:
|
idt_write:
|
||||||
lidt [rdi] ; first arg is the IDT pointer location
|
lidt [rdi] ; first arg is the IDT pointer location
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global idt_load: function hidden
|
global idt_load: function hidden (idt_load.end - idt_load)
|
||||||
idt_load:
|
idt_load:
|
||||||
sidt [rdi] ; first arg is where to write the idtr value
|
sidt [rdi] ; first arg is where to write the idtr value
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global gdt_write: function hidden
|
global gdt_write: function hidden (gdt_write.end - gdt_write)
|
||||||
gdt_write:
|
gdt_write:
|
||||||
lgdt [rdi] ; first arg is the GDT pointer location
|
lgdt [rdi] ; first arg is the GDT pointer location
|
||||||
|
|
||||||
@@ -27,9 +29,11 @@ gdt_write:
|
|||||||
.next:
|
.next:
|
||||||
ltr cx ; fourth arg is the TSS
|
ltr cx ; fourth arg is the TSS
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global gdt_load: function hidden
|
global gdt_load: function hidden (gdt_load.end - gdt_load)
|
||||||
gdt_load:
|
gdt_load:
|
||||||
sgdt [rdi] ; first arg is where to write the gdtr value
|
sgdt [rdi] ; first arg is where to write the gdtr value
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ bits 16
|
|||||||
default rel
|
default rel
|
||||||
align 8
|
align 8
|
||||||
|
|
||||||
global ap_startup: function hidden
|
global ap_startup: function hidden (ap_startup.end - ap_startup)
|
||||||
ap_startup:
|
ap_startup:
|
||||||
jmp .start_real
|
jmp .start_real
|
||||||
|
|
||||||
@@ -102,15 +102,16 @@ align 8
|
|||||||
|
|
||||||
mov rax, [BASE + (.ret - ap_startup)]
|
mov rax, [BASE + (.ret - ap_startup)]
|
||||||
jmp rax
|
jmp rax
|
||||||
|
.end:
|
||||||
|
|
||||||
|
|
||||||
global ap_startup_code_size: function hidden
|
global ap_startup_code_size: data hidden
|
||||||
ap_startup_code_size:
|
ap_startup_code_size:
|
||||||
dq ($ - ap_startup)
|
dq ($ - ap_startup)
|
||||||
|
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
global init_ap_trampoline: function hidden
|
global init_ap_trampoline: function hidden (init_ap_trampoline.end - init_ap_trampoline)
|
||||||
init_ap_trampoline:
|
init_ap_trampoline:
|
||||||
push rbp
|
push rbp
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
@@ -129,6 +130,7 @@ init_ap_trampoline:
|
|||||||
|
|
||||||
pop rbp
|
pop rbp
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
extern long_ap_startup
|
extern long_ap_startup
|
||||||
global ap_idle:function hidden (ap_idle.end - ap_idle)
|
global ap_idle:function hidden (ap_idle.end - ap_idle)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
%include "tasking.inc"
|
%include "tasking.inc"
|
||||||
|
|
||||||
global task_switch: function hidden
|
global task_switch: function hidden (task_switch.end - task_switch)
|
||||||
task_switch:
|
task_switch:
|
||||||
push rbp
|
push rbp
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
@@ -60,8 +60,10 @@ task_switch:
|
|||||||
|
|
||||||
pop rbp
|
pop rbp
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|
||||||
global _current_gsbase: function hidden
|
global _current_gsbase: function hidden (_current_gsbase.end - _current_gsbase)
|
||||||
_current_gsbase:
|
_current_gsbase:
|
||||||
mov rax, [gs:CPU_DATA.self]
|
mov rax, [gs:CPU_DATA.self]
|
||||||
ret
|
ret
|
||||||
|
.end:
|
||||||
|
|||||||
Reference in New Issue
Block a user