“.rodata.str1.4”的连接(link)有关问题
关于“.rodata.str1.4”的连接(link)问题
while(1) { unsigned char* s="abcd"; uart0_puts(s); }但在编译的时候出现了如下问题:
/usr/local/arm/3.4.1/bin/../lib/gcc/arm-linux/3.4.1/../../../../arm-linux/bin/ld: section .rodata.str1.4 [00000080 -> 0000008c] overlaps section .text [00000000 -> 0000044f]
【问题分析】
这个 .rodata.str1.4 是 -O2 优化时才出现的,不带优化选项时没有。在google上找到了如下一些资料:
Sections like .rodata.str1.4 are generated by gcc to support merging of duplicate constants and strings by ld. Older gcc's won't do this, nor will a newer gcc built for a system without the requisite ld support. it could be a matter of gcc versions. Apparently, gcc versions prior to 3.1.x didn't generate .rodata.strx.y sections.
大意为: .rodata.str1.4 是gcc为了支持ld合并重复的常量和字符串而产生的。老版本的gcc不会产生这个段,如果ld不支持,新版本的gcc也不会产生这个段,这是一个gcc版本问题。显然,3.1.x版本前的gcc不会产生 .rodata.strx.y段。
【解决办法】
在原来的连接脚本里边没加上 .rodata.str1。比如:
SECTIONS { . =0x00000000; .text : { *(.text) *(.rodata.str1.4) *(.rodata) } . =ALIGN(32); .data : { *(.data) } . =ALIGN(32); __bss_start__ = .; .bss : { *(.bss) } __bss_end__ = .; }【其他】
如果没有在在连接脚本里边加上 .rodata.str1.4 还可能出现如下错误:
/usr/local/arm/3.4.1/lib/gcc/arm-linux/3.4.1/../../../../arm-linux/bin/ld: error: no memory region specified for loadable section `.rodata.str1.4'
【参考资料】
http://telltruth.blogbus.com/logs/15705483.html
http://blog.chinaunix.net/uid-121788-id-2955078.html
http://blog.21ic.com/user1/2983/archives/2008/53972.html