This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
linker behaviour for sections having flags SHF_MERGE/SHF_STRINGS
- From: "shankarke at gmail dot com" <shankarke at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 9 Nov 2012 09:14:30 -0800 (PST)
- Subject: linker behaviour for sections having flags SHF_MERGE/SHF_STRINGS
Hi,
I was trying to understand the linker behaviour when sections have
SHF_MERGE/SHF_STRINGS property set.
Below are the test cases :-
merge_test.s
--------------
.section .rodata.str,"aMS","progbits",1
.LC0:
.asciz "abc"
.LC1:
.asciz "c"
.text
.global _start
_start:
.long .LC0
.LT0:
.long .LC1
.long .LC0-.LT0
.long .LC1-.LT0
$ readelf -p 5 merge_test.o
String dump of section '.rodata.str':
[ 0] abc
[ 4] c
$ ld merge_test.o
$ readelf -p 2 a.out
String dump of section '.rodata':
[ 0] abc
$gold merge_test.o
$ readelf -p 2 a.out
String dump of section '.rodata':
[ 0] abc
[ 4] c
Question :-
Why is the difference ?
Case 2
----------
merge_test.s
--------------
.section .rodata.str,"aM","progbits",3
.LC0:
.asciz "abc"
.LC1:
.asciz "abc"
.LC2:
.asciz "cde"
.LC3:
.asciz "cde"
.text
.global _start
_start:
.long .LC0
.LT0:
.long .LC1
.long .LC0-.LT0
.long .LC1-.LT0
$ ld merge_test.o
$ readelf -p 2 a.out
String dump of section '.rodata':
[ 0] abc
[ 4] abc
[ 8] cde
[ c] cde
Question :-
Isnt that the behaviour to expect abc, cde in the output
Case 3
---------
$ cat merge_test.s
.section .rodata.str,"aMS","progbits",2
.LC0:
.asciz "ab"
.LC1:
.asciz "ab"
.text
.global _start
_start:
.long .LC0
.LT0:
.long .LC1
.long .LC0-.LT0
.long .LC1-.LT0
$readelf -p 5 merge_test.o
String dump of section '.rodata.str':
[ 0] ab
[ 3] ab
$gold merge_test.o
gold: warning: merge_test.o: last entry in mergeable string section
'.rodata.str' not null terminated
$ld merge_test.o
(no error)
What is the linker expecting here ?
Other Questions:-
1) Are there documents that describe the behaviour when such
SHF_STRINGS/SHF_MERGE is set ?
2) Why is there a difference when I specify sh_entsize with sections having
SHF_STRINGS/SHF_MERGE flags ?
Thanks
Shankar Easwaran
--
View this message in context: http://sourceware-org.1504.n7.nabble.com/linker-behaviour-for-sections-having-flags-SHF-MERGE-SHF-STRINGS-tp212583.html
Sent from the Sourceware - binutils list mailing list archive at Nabble.com.