Incorrect line number info with --gc-sections

Bug #1451772 reported by Thomas Preud'homme
32
This bug affects 7 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

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.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

After investigation it appears that the problem comes from --gc-sections not removing the line info of functions inside sections it removed. These non removed line information are then interpreted as being related to the remaining code which break some of the assumptions made about line information.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.