Bug 11002 - ld string merge does not respect symbol size
Summary: ld string merge does not respect symbol size
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-23 11:12 UTC by Nuno Lopes
Modified: 2009-11-23 14:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2009-11-23 11:12:56 UTC
$ cat a.s
        .file   "a.c"
        .type   a,@object
        .section        .rodata.str1.1,"aMS",@progbits,1
        .globl a
a:
        .size   a, 5  # note that size is 5!
        .align  8
        .byte   0x61
        .byte   0x62
        .zero   1
        .type   b,@object
        .globl b
b:
        .size   b, 2
        .byte   0x62
        .zero   1

        .section        .note.GNU-stack,"",@progbits

$ as -o a.o a.s
$ ld -shared -o a.so a.o
$ readelf -a a.o
(...)
     7: 00000000     5 OBJECT  GLOBAL DEFAULT    4 a
     8: 00000003     2 OBJECT  GLOBAL DEFAULT    4 b
(note that 'a' has size 5)

$ objdump -s a.so
Contents of section .rodata:
 0160 61620000 00000000                    ab......

As you can see, the value for the symbol 'a' is broken. It should be 'ab\0b\0'.
Comment 1 Andreas Schwab 2009-11-23 12:19:37 UTC
The contents of "MS" sections must be zero-terminated strings.
Comment 2 Nuno Lopes 2009-11-23 14:40:54 UTC
(In reply to comment #1)
> The contents of "MS" sections must be zero-terminated strings.

which they are:
a = 'ab\0b\0'
b = 'b\0'
Comment 3 Andreas Schwab 2009-11-23 14:48:40 UTC
> a = 'ab\0b\0'

This is not a valid zero-terminated string.