gcc设置段基址

gcc设置段基址

@(编译相关)[gcc设置段基址]


[TOC]


设置代码段基址

向gcc/g++中传入这个命令行选项:-Wl,-Ttext-segment=<地址>,-Wl表示这个命令行选项是传给链接器(即,ld)的。

命令行选项说明

查找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'。

起始地址可以理解为基址

我没有找到"-Ttext-segment"这个命令行选项,我认为"-Ttext-segment"与"-Ttext"表示同一个意思。

例子

使用下面的命令,gcc编译出来的ELF文件的text段基址为0x60000000:

gcc -Wl,-Ttext-segment=0x60000000 ...

转载于:https://my.oschina.net/ibuwai/blog/653283

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值