Nonsense line numbers with --gc-sections

Asked by Neil

When I link with -Wl,--gc-sections, some of the line numbers (as reported by arm-none-eabi-objdump -dl) are incorrect. I initially encountered this with 4.8-2014-q1 but it is also reproducible with 4.9-2015-q1-update.

00000150 <mpu_init>:
mpu_init():
C:\Downloads\cdtfiles\cdt208261\foo\test/main.c:50
 150: b580 push {r7, lr}
 152: af00 add r7, sp, #0
 154: 2300 movs r3, #0
 156: 1c18 adds r0, r3, #0
 158: 46bd mov sp, r7
 15a: bd80 pop {r7, pc}

0000015c <main>:
main():
C:\Downloads\cdtfiles\cdt208261\foo\test/main.c:51
 15c: b580 push {r7, lr}
 15e: af00 add r7, sp, #0
 160: f7ff fff6 bl 150 <mpu_init>
C:\Downloads\cdtfiles\cdt208261\foo\test/main.c:61 (discriminator 1)
 164: e7fe b.n 164 <main+0x8>
unused_function():
 166: 46c0 nop ; (mov r8, r8)

In the actual source code, mpu_init is actually at 18-21 and main is at 63-70 (there is an unused function at 23-61).

A simplified version of the project:
https://onedrive.live.com/redir?resid=5089c7918c88c974!115&authkey=!AN7dF0QaqO7FL5g&ithint=file%2ctgz

The linker script is a slightly modified version of the default linker script (it does not currently place the data at 0x20000000 as required by the target hardware but that should not be required for reproducing this issue). The line numbers are correct when linking without the --gc-sections option.

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Neil,

I can indeed reproduce the problem but not with the same toolchain updating binutils to 2.25. It was maybe fixed between 2.24 and 2.25. I'll investigate.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#2

Hi Neil,

I wonder if this is not related to your linker script. I see that you discard some debugging info in it. When I link without it the line numbers are fine so I suspect the error might come from your linker script.

Best regards.

Revision history for this message
Neil (neilt) said :
#3

The only differences between the included linker script and the default linker script are:
1. Includes the .romvectors section (doesn't seem to affect this issue)
2. Changes start address to 0 (default uses 0x8000 and doesn't seem to have the line number problem).

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#4

Hi Neil,

I investigated some more and am leaning towards an error in objdump. Indeed, arm-none-eabi-readelf -WL output.axf shows the correct line information. Although much less convenient I suggest you make use of this option when in need of correct line information in the mean time.

Best regards.

Can you help with this problem?

Provide an answer of your own, or ask Neil for more information if necessary.

To post a message you must log in.