Improve cake allocator's memory utilisation (#43)
[lunaix-os.git] / lunaix-os / scripts / gen_ksymtable.sh
index 6b59e4d71ea0eaba6daa95d35e99bdc3a5dad2a7..748678e5e09a1b82207f3273386693bcc76a7400 100755 (executable)
@@ -1,12 +1,19 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 sym_types=$1
 bin=$2
 
 nm_out=$(nm -nfbsd "$bin")
+# class_info=$(readelf -h "$bin" | grep 'Class:' | awk '{print $2}')
+
 allsyms=($nm_out)
 allsyms_len=${#allsyms[@]}
 
+dtype="4byte"
+if [ "$ARCH" == 'x86_64' ]; then
+    dtype="8byte"
+fi
+
 syms_idx=()
 
 for (( i=0; i<allsyms_len; i+=3));
@@ -24,7 +31,7 @@ declare -A assoc_array
 echo '.section .ksymtable, "a", @progbits'
 echo "    .global __lunaix_ksymtable"
 echo "    __lunaix_ksymtable:"
-echo "        .long $syms_len"
+echo "        .$dtype $syms_len"
 echo "        .align 8"
 
 for i in "${syms_idx[@]}"
@@ -33,22 +40,20 @@ do
     type=${allsyms[$i + 1]}
     sym=${allsyms[$i + 2]}
 
-    echo "$(cat <<EOF
-        .long 0x$addr
-        .long __S$sym
+    cat <<EOF
+        .$dtype 0x$addr
+        .$dtype __S$sym
         .align 8
 
 EOF
-)"
     assoc_array["$sym"]=1
 done
 
 for sym_str in "${!assoc_array[@]}"
 do
-    echo "$(cat <<EOF
+    cat <<EOF
     __S$sym_str:
         .asciz "$sym_str"
         .align 8
 EOF
-)"
 done
\ No newline at end of file