@(編譯相關)[gcc設置段基址]html
[TOC]node
向gcc/g++中傳入這個命令行選項:-Wl,-Ttext-segment=<地址>
,-Wl表示這個命令行選項是傳給連接器(即,ld)的。shell
查找ld的命令行選項手冊(https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html#SEC3)可找到下面的說明:命令行
-Tbss org -Tdata org -Ttext org Use org as the starting address for--respectively--the bss, data, or the text segment of the output file. org must be a single hexadecimal integer; for compatibility with other linkers, you may omit the leading `0x' usually associated with hexadecimal values.
上面英文的意思是:使用org做爲輸出文件的bss,data或text段的起始地址。org必須是一個十六進制整數;爲了與其餘連接器兼容,不要在十六進制數的前面添加'0x'。code
起始地址能夠理解爲基址。htm
我沒有找到"-Ttext-segment"這個命令行選項,我認爲"-Ttext-segment"與"-Ttext"表示同一個意思。ci
使用下面的命令,gcc編譯出來的ELF文件的text段基址爲0x60000000:get
gcc -Wl,-Ttext-segment=0x60000000 ...