在汇编语言中,我使用.section指令告诉汇编器输出到哪个部分,例如
.section init
Run Code Online (Sandbox Code Playgroud)
有没有办法在C文件中做同样的事情.我希望某些文件的代码进入不同的部分,以便我可以将其加载到不同的内存地址.我知道我可以为ld创建一个脚本并在那里指定部分,但我不想这样做.是否有一些编译器开关或.section指令类型的C文件将执行此操作?
Mat*_*lin 16
有:
__attribute__((section("section_name")))
Run Code Online (Sandbox Code Playgroud)
所以,例如:
void foo() __attribute__((section(".text_foo")));
....
void foo() {}
Run Code Online (Sandbox Code Playgroud)
将放置foo在.text_foo
有关更多信息,请参见此处