I'm trying to track down an optimization bug.

I have written a D program and a C program that are essentially identical, and compiled them to assembly code with my arm-none-eabi-gdc/gcc build.

C Code: https://bpaste.net/show/6f420de3a892
C ASM : https://bpaste.net/show/42c75f6763bf
arm-none-eabi-gcc -O1 -S -ffunction-sections test.c -o test.s


D Code: https://bpaste.net/show/20faec5c4bb6
D ASM : https://bpaste.net/show/b2c200705d5d
arm-none-eabi-gdc -O1 -S -ffunction-sections test.d -o test.d.s

The problem is with the string literals at the very end of the ASM files:

C
****
.L12:
        .align  2
.L11:
        .word   .LC1
        .word   .LC2
        .word   .LC3
        .size   _start, .-_start
        .section        .rodata.str1.4,"aMS",%progbits,1
        .align  2
.LC0:
        .ascii  "\015\012\000"
        .space  1
.LC1:
        .ascii  "a\000"
        .space  2
.LC2:
        .ascii  "another string\000"
        .space  1
.LC3:
        .ascii  "do it again\000"
        .ident  "GCC: (GNU) 4.9.2"

D
****
.L6:
        .word   .LANCHOR0

... { blah blah }

.L13:
        .align  2
.L12:
        .word   .LANCHOR0
        .cantunwind
        .fnend
        .size   _D5start6_startFZv, .-_D5start6_startFZv
        .section        .rodata
        .align  2
        .set    .LANCHOR0,. + 0
.LC0:
        .ascii  "\015\012"
        .space  2
.LC1:
        .ascii  "a"
        .space  3
.LC2:
        .ascii  "another string"
        .space  2
.LC3:
        .ascii  "do it again"
        .ident  "GCC: (GNU) 4.9.2"

Notice how the D code adds the section anchor .LANCHOR0, but the C code does not.

The D code then refers to the sting literals with something like this...
ldr     r3, .L6
add     r3, sp, #16
... essentially referring to the string literal as an offset from .LANCHOR

This is causing a problem for me because if I put my string literals in separate sections (i.e. -fdata-sections), compile with -O1 (i.e. -fsection-anchors), and link with --gc-section, then the linker strips out my string literals because it doesn't see the link to the string literal. (At least that's my theory).

The C code, on the other hand, does not use the section anchor and instead seems to put them in some kind of array of strings like this:
.L11:
        .word   .LC1
        .word   .LC2
        .word   .LC3

Therefore, the linker can see the link to the string literals and doesn't strip them out (Again, that's my theory)

Can anything be done about this in GDC?

Thanks always for the help,
Mike

Reply via email to