歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> perf交叉編譯 arm

perf交叉編譯 arm

日期:2017/3/3 12:41:24   编辑:Linux技術

文件改動配置方法基本與,perf使用arm-hisiv200-linux工具鏈類似。

但是由於arm-hisiv400-linux工具鏈編譯時,問題更多。主要記錄交叉編譯終於到的問題,或解決或繞過。

perf 工具需要zlib、binutils、elfutils庫支持。

我主機上的arm-hisiv400-linux-的交叉工具鏈已經支持zlib、binutils庫,所以只需要做elfutils的交叉編譯即可。

交叉編譯elfutils

使用elfutils-0.148.tar.bz2(目前最新) 下載地址:https://fedorahosted.org/releases/e/l/elfutils/

tar -xvjf elfutils-0.148.tar.bz2

<pre name="code" class="cpp">cd elfutils-0.148
./configure --host=arm-hisiv400-linux --prefix=/xxx/elfutils_tool/elfutils_target --exec-prefix=/xxx/elfutils_tool/elfutils_target

注意:--host=arm-hisiv400-linux 沒有-

按照上篇文章提到的

、、、、、、、、、、、、、、、、、、、、上文提到的、、、、、、、、、、、、、、、、、、、、、、、、、

修改elfutils-0.148 目錄下Makefile 根目錄下makefile ,修改過程-》

# Add doc back when we have some real content.
SUBDIRS = config m4 lib libelf libebl libdwfl libdw libcpu libasm backends \
	  src po tests
將libcpu去掉。改為
# Add doc back when we have some real content.
SUBDIRS = config m4 lib libelf libebl libdwfl libdw libasm backends \
	  src po tests

修改elfutils-0.148/backends/下makefile

如左圖中修改,右圖中作為對照 ,主要是去掉i386 和x86_64 相關內容,不然各種錯誤。

、、、、、、、、、、、、、、、、、、、上篇文章提到的、、、、、、、、、、、、、、、、、、、、、、、、、、、

make

遇到第一個問題

md5.c:108:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
cc1: all warnings being treated as errors
解決這個問題可以根據https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684825提到的解決方法打https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=15;filename=bug684825.patch;bug=684825;att=1這個patch

也可以修改相應makefile,中的Werror CFLAGS 選項 將其去掉。

我打的patch,比較笨的方法。

修改makefile的話 將\elfutils-0.148\lib

下makfile

<pre name="code" class="cpp">AM_CFLAGS = -std=gnu99 -Wall -Wshadow $(if \
	$($(*F)_no_Werror),,-Werror) $(if \
	$($(*F)_no_Wunused),,-Wunused -Wextra) $(if \
	$($(*F)_no_Wformat),-Wno-format,-Wformat=2) $($(*F)_CFLAGS) \
	$(am__append_1) -fpic
修改如下,刪除-Werror

AM_CFLAGS = -std=gnu99 -Wall -Wshadow $(if \
	$($(*F)_no_Werror),,) $(if \
	$($(*F)_no_Wunused),,-Wunused -Wextra) $(if \
	$($(*F)_no_Wformat),-Wno-format,-Wformat=2) $($(*F)_CFLAGS) \
	$(am__append_1) -fpic
繼續make 你會發現 還有類似的錯誤 都是Werror編譯選項導致的,我在根目錄的makefile沒有找到去除這個選項的方法,就直接在出現
cc1: all warnings being treated as errors

錯誤的文件夾內修改對應的makefile,修改方式按照上文提到的方式,刪除-Werror即可。

修改的文件有elfutils-0.148\libasm\Makefile

、elfutils-0.148\src\Makefile.

修正後即可編譯成功。

執行make install

完成elfutils庫的交叉編譯。

perf交叉編譯。

進入linux-3.10.y/tools/perf目錄

修改Makefile ,如果編譯器編譯太嚴格的的話,把warning,判定為error ,可以把 CFLAGS中$(CFLAGS_WERROR)刪除。

CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
EXTLIBS = -lpthread -lrt -lelf -lm -lebl -ldl -L/xxx/elfutils_tool/elfutils_target/lib 
ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/xxx/elfutils_tool/elfutils_target/include
ALL_LDFLAGS = $(LDFLAGS)
make LDFLAGS=-static ARCH=arm CROSS_COMPILE=arm-hisiv400-linux- DEBUG=1 LIBDW_DIR=/xxx/elfutils_tool/elfutils_target HAVE_CPLUS_DEMANGLE=1

遇到flex的問題,見上章解決介紹,

遇到debugfs.c 文件編譯時linux/magic.h找不到的話,就把linux-3.10.y/tools/lib/lk 目錄下的debugfs.c //#include <linux/magic.h>注釋掉。

遇到arm-hisiv400-linux-ld鏈接 時 提示 debugfs.o格式不正確的問題,可以到linux-3.10.y/tools/lib/lk 目錄下

執行file debugfs.o 看看debugfs.o 是不是arm版本的,如果確定不是,可以直接執行arm-hisiv400-linux-gcc -c debugfs.c生成arm版本的debugfs.o,回到elfutils-0.148\下繼續make。

遇到找不到-lebl 庫找不到的話,可以直接在elfutils-0.148/目錄下修改makefile

如下

EXTLIBS = -lpthread -lrt -lelf -lm -lebl

-ldl -L/user1/yueyc/elfutils_tool/elfutils_target/lib

修改為

EXTLIBS = -lpthread -lrt -lelf -lm -ldl

-L/user1/yueyc/elfutils_tool/elfutils_target/lib

這個問題花費了很長的時間,因為在elfutils_target/lib 中的確有libebl.a 靜態庫,看到了其他不報找不到的庫都有動態庫的文件。進行了如下幾個嘗試。

使用arm-hisiv400-linux-ar -x libebl.a

指令將靜態庫打散成*.o 文件,然後使用*.o 生成動態庫,並建立連接文件,依舊不可以

嘗試如下方式,不起作用

cp libebl.a libebl1.a
arm-hisiv400-linux-ar -x libebl1.a
arm-hisiv400-linux-gcc -shared *.o -o libebl.so
嘗試如下方式,也不起作用

cp libebl.a libebl1.a
arm-hisiv400-linux-ar -x libebl1.a
arm-hisiv400-linux-gcc -shared *.o -o libebl.so.1
ln -fs libebl.so.1 libebl.so
想嘗試一下在makefile下直接生成動態庫,makefile書寫入門水平。

嘗試了一下將Makefile中   -lebl刪除,神奇的成功的制作出了perf工具,在Hi3536平台上一測試可用。
如果哪位高手,正規的解決了中間過程中提到的問題,勞煩留言告知,謝謝各位看官。

Copyright © Linux教程網 All Rights Reserved