This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] Print source when subsequent lines in the translation unit come from the same line in two different headers.
ClosedPublic

Authored by mmpozulp on May 25 2019, 11:46 PM.

Details

Summary

If you have these files

header1.h

int add1(int a) { return a + 1; }

header2.h

int return4() { return 4; }

test.c

#include "header1.h"
#include "header2.h"

and compile them with clang -g -c test.c -o test.o and run llvm-objdump --source test.o, the source from header2.h is missing

0000000000000000 add1:
; int add1(int a) { return a + 1; }
       0: 55                           	pushq	%rbp
       1: 48 89 e5                     	movq	%rsp, %rbp
       4: 89 7d fc                     	movl	%edi, -4(%rbp)
       7: 8b 45 fc                     	movl	-4(%rbp), %eax
       a: 83 c0 01                     	addl	$1, %eax
       d: 5d                           	popq	%rbp
       e: c3                           	retq
       f: 90                           	nop

0000000000000010 return4:
      10: 55                           	pushq	%rbp
      11: 48 89 e5                     	movq	%rsp, %rbp
      14: b8 04 00 00 00               	movl	$4, %eax
      19: 5d                           	popq	%rbp
      1a: c3                           	retq

This patch fixes this problem, interleaving the source from header2.h

0000000000000000 add1:
; int add1(int a) { return a + 1; }
       0: 55                           	pushq	%rbp
       1: 48 89 e5                     	movq	%rsp, %rbp
       4: 89 7d fc                     	movl	%edi, -4(%rbp)
       7: 8b 45 fc                     	movl	-4(%rbp), %eax
       a: 83 c0 01                     	addl	$1, %eax
       d: 5d                           	popq	%rbp
       e: c3                           	retq
       f: 90                           	nop

0000000000000010 return4:
; int return4() { return 4; }
      10: 55                           	pushq	%rbp
      11: 48 89 e5                     	movq	%rsp, %rbp
      14: b8 04 00 00 00               	movl	$4, %eax
      19: 5d                           	popq	%rbp
      1a: c3                           	retq

FYI I noticed this bug while working on a different patch requested by @jhenderson (https://bugs.llvm.org/show_bug.cgi?id=41905).

Diff Detail

Repository
rL LLVM

Event Timeline

mmpozulp created this revision.May 25 2019, 11:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2019, 11:46 PM
grimar accepted this revision.May 27 2019, 3:08 AM

This LGTM. But please hold this on until anyone else take a look too.

This revision is now accepted and ready to land.May 27 2019, 3:08 AM

This LGTM. But please hold this on until anyone else take a look too.

Thanks, @grimar. Holding on...

jhenderson accepted this revision.Jun 4 2019, 4:40 AM

LGTM, good catch! I think you can revise your summary to change headers to files, since it could happen in other cases too.

Will do. Sorry for the delay, I'm fighting with svn. See my comment in https://reviews.llvm.org/D62369.

mmpozulp updated this revision to Diff 203498.Jun 6 2019, 11:00 PM

Incorporate feedback from @jhenderson to change 'headers' to 'files' in test description.

This revision was automatically updated to reflect the committed changes.

Committed as r362771.