GNU LD指定symbol address

Posted on 週三 23 三月 2016 in Archive

在Embedded System有時候會需要強制修改shared object用到的OS routine symbol address 讓他可以指到routine在image裡的位置

一樣是參考手冊,找到這個option: --just-symbols=filename

Read symbol names and their addresses from filename, but do not relocate it or include it in the output. This allows your output file to refer symbolically to absolute locations of memory defined in other programs. You may use this option more than once. For compatibility with other ELF linkers, if the -R option is followed by a directory name, rather than a file name, it is treated as the -rpath option.

.........但是你沒講filename是什麼東西啊 =皿=

後來在這找到symbol file的format:

symbol1 = 0x12345678;
symbol2 = 0x23456789;
...

其中等號旁的空白是必須的,如果format不對的話ld會噴error說他看不懂

用了這個之後,link出來的symbol就會從UND變成ABS啦

當然也可以用--defsym symbol=0x12345678,但是symbol一多的時候還是用symbol file比較快