From 81c77586c64f65209ad8161c8b2b0ab335c3eb5a Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sat, 15 Jun 2019 23:42:57 +0800 Subject: [PATCH] Adapt fill_symbols for macOS --- kernel/Makefile | 2 +- kernel/src/process/structs.rs | 8 +++----- tools/fill_symbols/x86_64.sh | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 6d0c75db..516a0844 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -337,7 +337,7 @@ kernel: $(dtb) ifeq ($(arch), x86_64) @bootimage build $(build_args) @echo "Now patching kernel symbols onto kernel." - ../tools/fill_symbols/x86_64.sh target/x86_64/$(mode)/rcore + @../tools/fill_symbols/x86_64.sh target/x86_64/$(mode)/rcore @echo "Generate bootimage again." @bootimage build $(build_args) @mv target/x86_64/bootimage.bin $(bootimage) diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index 43f66540..44608f52 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -189,8 +189,9 @@ impl Thread { let (mut vm, bias) = elf.make_memory_set(inode); // Check interpreter (for dynamic link) + // When interpreter is used, map both dynamic linker and executable if let Ok(loader_path) = elf.get_interpreter() { - info!("Handling interpreter... bias={:x}", bias); + info!("Handling interpreter... offset={:x}", bias); // assuming absolute path let interp_inode = crate::fs::ROOT_INODE .lookup_follow(loader_path, FOLLOW_MAX_DEPTH) @@ -203,12 +204,11 @@ impl Thread { .map_err(|_| "failed to read from INode")?; let elf_interp = ElfFile::new(&interp_data)?; elf_interp.append_as_interpreter(&interp_inode, &mut vm, bias); - info!("entry: {:x}", elf.header.pt2.entry_point() as usize); + debug!("entry point: {:x}", elf.header.pt2.entry_point() as usize); auxv.insert(abi::AT_ENTRY, elf.header.pt2.entry_point() as usize); auxv.insert(abi::AT_BASE, bias); entry_addr = elf_interp.header.pt2.entry_point() as usize + bias; } - debug!("{:#x?}", vm); // User stack use crate::consts::{USER_STACK_OFFSET, USER_STACK_SIZE}; @@ -239,8 +239,6 @@ impl Thread { vm.with(|| ustack_top = init_info.push_at(ustack_top)); } - trace!("{:#x?}", vm); - Ok((vm, entry_addr, ustack_top)) } diff --git a/tools/fill_symbols/x86_64.sh b/tools/fill_symbols/x86_64.sh index a4a7eee6..618ba9d1 100755 --- a/tools/fill_symbols/x86_64.sh +++ b/tools/fill_symbols/x86_64.sh @@ -1,13 +1,26 @@ #!/bin/bash +objdump=objdump +nm=nm +if [[ "$OSTYPE" == "darwin"* ]]; then + objdump=/usr/local/opt/binutils/bin/objdump + nm=/usr/local/opt/binutils/bin/nm + if hash $objdump 2>/dev/null; then + echo "Found GNU objdump" + else + echo "No GNU objdump found, use brew install binutils" + exit 1 + fi +fi + echo "Filling kernel symbols." rcore=$1 tmpfile=$(mktemp /tmp/rcore-symbols.txt.XXXXXX) echo "Writing symbol table." -nm $1 >$tmpfile +$nm $1 >$tmpfile gzip $tmpfile tmpfile=$tmpfile.gz -symbol_table_loc=$((16#$(objdump -D $rcore -j .data -F |grep "" |grep -oEi "0x[0-9a-f]+" |grep -oEi "[0-9a-f][0-9a-f]+"))) -symbol_table_size_loc=$((16#$(objdump -D $rcore -j .data -F |grep "" |grep -oEi "0x[0-9a-f]+" |grep -oEi "[0-9a-f][0-9a-f]+"))) +symbol_table_loc=$((16#$($objdump -D $rcore -j .data -F |grep "" |grep -oEi "0x[0-9a-f]+" |grep -oEi "[0-9a-f][0-9a-f]+"))) +symbol_table_size_loc=$((16#$($objdump -D $rcore -j .data -F |grep "" |grep -oEi "0x[0-9a-f]+" |grep -oEi "[0-9a-f][0-9a-f]+"))) echo $symbol_table_loc echo $symbol_table_size_loc FILESIZE=$(stat -c%s "$tmpfile")