Port gen_gtp_data.sh to 64-bits 31/110731/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 16 Jan 2017 13:24:50 +0000 (16:24 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 23 Jan 2017 11:56:55 +0000 (14:56 +0300)
Change-Id: I8c19a03953caac6e126e6d31622aab10569a7c9e
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
scripts/gen_gtp_data.sh

index 745959c..9cf1265 100755 (executable)
@@ -10,6 +10,18 @@ libpthread_init_func="__pthread_initialize_minimal"
 output=$1
 
 
+is64bit()
+{
+    readelf -h $handlers_lib | grep "Class:" | grep ELF64 > /dev/null
+    return $?
+}
+
+to_swap_format()
+{
+    addr=$1
+    is64bit && addr=$(echo $addr | sed 's/0x0/0x8/')
+    echo $addr
+}
 
 function print_header()
 {
@@ -31,7 +43,8 @@ function print_dl_fixup_off()
 {
     filename=$1
 
-    addr=$(cat $linker_info_header | grep "dl_fixup_off" | grep -o "0x[0-9a-f]\{8\}")
+    addr=$(cat $linker_info_header | grep "dl_fixup_off" | grep -o "0x[0-9a-f]*")
+    addr=$(to_swap_format $addr)
     echo -e "/bin/echo \"$addr\" > /sys/kernel/debug/swap/got_patcher/linker/dl_fixup_addr" >> $filename
 }
 
@@ -39,7 +52,8 @@ function print_dl_reloc_off()
 {
     filename=$1
 
-    addr=$(cat $linker_info_header | grep "dl_reloc_off" | grep -o "0x[0-9a-f]\{8\}")
+    addr=$(cat $linker_info_header | grep "dl_reloc_off" | grep -o "0x[0-9a-f]*")
+    addr=$(to_swap_format $addr)
     echo -e "/bin/echo \"$addr\" > /sys/kernel/debug/swap/got_patcher/linker/dl_reloc_addr" >> $filename
 }
 
@@ -54,7 +68,7 @@ function print_dl_fixup_handler_off()
 {
     filename=$1
 
-    addr=$(readelf -sW $handlers_lib | grep $fixup_handler | awk '{print "0x" $2}')
+    addr=$(parse_elf -f $handlers_lib --addr_format=swap --syms | grep $fixup_handler | awk '{print "0x" $1}')
     echo -e "/bin/echo \"$addr\" > /sys/kernel/debug/swap/got_patcher/handler/fixup_handler_off" >> $filename
 }
 
@@ -62,7 +76,7 @@ function print_dl_reloc_handler_off()
 {
     filename=$1
 
-    addr=$(readelf -sW $handlers_lib | grep $reloc_handler | awk '{print "0x" $2}')
+    addr=$(parse_elf -f $handlers_lib --addr_format=swap --syms | grep $reloc_handler | awk '{print "0x" $1}')
     echo -e "/bin/echo \"$addr\" > /sys/kernel/debug/swap/got_patcher/handler/reloc_handler_off" >> $filename
 }
 
@@ -71,7 +85,7 @@ function print_libpthread()
     filename=$1
 
     libpthread_path=$(rpm -ql $libpthread_pkg_name | grep "/${LIB}/libpthread" | head -1)
-    addr=$(readelf -sW $libpthread_path | grep $libpthread_init_func | awk '{print "0x" $2}')
+    addr=$(parse_elf -f $libpthread_path --addr_format=swap --syms | grep $libpthread_init_func | awk '{print "0x" $1}')
 
     echo -e "/bin/echo \"$libpthread_path\" > /sys/kernel/debug/swap/got_patcher/pthread/path" >> $filename
     echo -e "/bin/echo \"$addr\" > /sys/kernel/debug/swap/got_patcher/pthread/minimal_init_off" >> $filename