[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Wrong source when using `-S` in objdump
From: |
Alan Modra |
Subject: |
Re: Wrong source when using `-S` in objdump |
Date: |
Mon, 11 Apr 2016 11:19:35 +0930 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Fri, Apr 08, 2016 at 06:25:23PM +0200, Albert Netymk wrote:
> test.c
> ```
> void my_fun(int *arr, int N)
> {
> int sum = 0;
> for (int i = 0; i < N; ++i) {
> sum += arr[i];
> }
> }
>
> int main(void)
> {
> return 0;
> }
> ```
> clang -c -g test.c ; objdump -S test.o > test.s
>
> `my_fun` appears twice in the disassembly code.
> Excerpt of test.s:
[snip]
Please take a look at the .debug_line info in your object file with
"readelf -wl test.o". I expect you will see negative advances of line
number, at the address where you see repeated source lines. This is
normal. Compilers will emit code corresponding to a single line, at
different locations. This happens even at -O0, particularly around
loops.
So you should expect this line
for (int i = 0; i < N; ++i) {
to be repeated.
objdump also shows some context lines before the repeated line.
That's why my_fun appears twice. We could probably fix that.
You'll also notice repeated source lines after the negative advance of
line number that don't actually corresponded to code at those
locations. In this case
sum += arr[i];
We can't do much about that..
--
Alan Modra
Australia Development Lab, IBM