clang may generate incorrect dwarf info?

Function signature in FreeBSD source code:
void _sx_xunlock(struct sx *sx, const char *file, int line);

DWARF (reported by objdump -x -w -W) when compiled with gcc:
<1><8337>: Abbrev Number: 63 (DW_TAG_subprogram)
  <8338> DW_AT_external : 1
  <8339> DW_AT_name : (indirect string, offset: 0x48c9): _sx_xunlock
  <833d> DW_AT_decl_file : 1
  <833e> DW_AT_decl_line : 373
  <8340> DW_AT_prototyped : 1
  <8341> DW_AT_low_pc : 0x13a7
  <8349> DW_AT_high_pc : 0x143e
  <8351> DW_AT_frame_base : 0x3cd3 (location list)
  <8355> DW_AT_sibling : <84a4>
<2><8359>: Abbrev Number: 59 (DW_TAG_formal_parameter)
  <835a> DW_AT_name : sx
  <835d> DW_AT_decl_file : 1
  <835e> DW_AT_decl_line : 372
  <8360> DW_AT_type : <2cac>
  <8364> DW_AT_location : 0x3d1f (location list)
<2><8368>: Abbrev Number: 60 (DW_TAG_formal_parameter)
  <8369> DW_AT_name : (indirect string, offset: 0x9016): file
  <836d> DW_AT_decl_file : 1
  <836e> DW_AT_decl_line : 372
  <8370> DW_AT_type : <1ea>
  <8374> DW_AT_location : 0x3d8e (location list)
<2><8378>: Abbrev Number: 60 (DW_TAG_formal_parameter)
  <8379> DW_AT_name : (indirect string, offset: 0x12a): line
  <837d> DW_AT_decl_file : 1
  <837e> DW_AT_decl_line : 372
  <8380> DW_AT_type : <5f>
  <8384> DW_AT_location : 0x3dd7 (location list)

Ditto when compiled with clang:
<1><2c70>: Abbrev Number: 55 (DW_TAG_subprogram)
  <2c71> DW_AT_name : (indirect string, offset: 0x1817): _sx_xunlock
  <2c75> DW_AT_decl_file : 1
  <2c76> DW_AT_decl_line : 373
  <2c78> DW_AT_prototyped : 1
  <2c78> DW_AT_external : 1
  <2c78> DW_AT_inline : 1 (inlined)
<2><2c79>: Abbrev Number: 51 (DW_TAG_formal_parameter)
  <2c7a> DW_AT_name : (indirect string, offset: 0xd061): line
  <2c7e> DW_AT_decl_file : 1
  <2c7f> DW_AT_decl_line : 373
  <2c81> DW_AT_type : <a2>
<2><2c85>: Abbrev Number: 51 (DW_TAG_formal_parameter)
  <2c86> DW_AT_name : (indirect string, offset: 0xd056): sx
  <2c8a> DW_AT_decl_file : 1
  <2c8b> DW_AT_decl_line : 373
  <2c8d> DW_AT_type : <782c>
<2><2c91>: Abbrev Number: 51 (DW_TAG_formal_parameter)
  <2c92> DW_AT_name : (indirect string, offset: 0xc67): file
  <2c96> DW_AT_decl_file : 1
  <2c97> DW_AT_decl_line : 373
  <2c99> DW_AT_type : <32>

First, looks like the parameters come in a wrong order.

[snip]

What's the actual definition look like?

ghostwheel:~/tmp> cat foo.c
void _sx_xunlock(struct sx *sx, const char *file, int line) {}

0x00000026: TAG_subprogram [2] *
                 AT_name( "_sx_xunlock" )
                 AT_decl_file( "/Users/echristo/tmp/foo.c" )
                 AT_decl_line( 1 )
                 AT_prototyped( 0x01 )
                 AT_external( 0x01 )
                 AT_low_pc( 0x0000000000000000 )
                 AT_high_pc( 0x0000000000000011 )
                 AT_frame_base( rbp )

0x00000041: TAG_formal_parameter [3]
                     AT_name( "sx" )
                     AT_decl_file( "/Users/echristo/tmp/foo.c" )
                     AT_decl_line( 1 )
                     AT_type( {0x00000072} ( sx* ) )
                     AT_location( fbreg -8 )

0x0000004f: TAG_formal_parameter [3]
                     AT_name( "file" )
                     AT_decl_file( "/Users/echristo/tmp/foo.c" )
                     AT_decl_line( 1 )
                     AT_type( {0x00000083} ( const char* ) )
                     AT_location( fbreg -16 )

0x0000005d: TAG_formal_parameter [3]
                     AT_name( "line" )
                     AT_decl_file( "/Users/echristo/tmp/foo.c" )
                     AT_decl_line( 1 )
                     AT_type( {0x00000088} ( int ) )
                     AT_location( fbreg -20 )

0x0000006b: NULL

with current clang.

-eric

on 03/04/2013 18:17 Eric Christopher said the following:

What's the actual definition look like?

ghostwheel:~/tmp> cat foo.c
void _sx_xunlock(struct sx *sx, const char *file, int line) {}

A full preprocessed file along with .o can be found here:
http://people.freebsd.org/~avg/kern_sx.tgz

Command line options:
-pipe -fno-strict-aliasing -march=amdfam10 -std=c99 -g -O -Wall -Wredundant-decls
-Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline
-Wcast-qual -Wundef -Wno-pointer-sign -fformat-extensions -Wmissing-include-dirs
-fdiagnostics-show-option -Wno-error-tautological-compare -Wno-error-empty-body
-Wno-error-parentheses-equality -nostdinc -fno-omit-frame-pointer
-mno-omit-leaf-frame-pointer -mno-aes -mno-avx -mcmodel=kernel -mno-red-zone
-mno-mmx -mno-sse -msoft-float -fno-asynchronous-unwind-tables -ffreestanding
-fstack-protector -Werror

clang is from FreeBSD tree:
FreeBSD clang version 3.2 (tags/RELEASE_32/final 170710) 20121221

0x00000026: TAG_subprogram [2] *
                 AT_name( "_sx_xunlock" )
                 AT_decl_file( "/Users/echristo/tmp/foo.c" )
                 AT_decl_line( 1 )
                 AT_prototyped( 0x01 )
                 AT_external( 0x01 )
                 AT_low_pc( 0x0000000000000000 )
                 AT_high_pc( 0x0000000000000011 )
                 AT_frame_base( rbp )

0x00000041: TAG_formal_parameter [3]
                     AT_name( "sx" )
                     AT_decl_file( "/Users/echristo/tmp/foo.c" )
                     AT_decl_line( 1 )
                     AT_type( {0x00000072} ( sx* ) )
                     AT_location( fbreg -8 )

0x0000004f: TAG_formal_parameter [3]
                     AT_name( "file" )
                     AT_decl_file( "/Users/echristo/tmp/foo.c" )
                     AT_decl_line( 1 )
                     AT_type( {0x00000083} ( const char* ) )
                     AT_location( fbreg -16 )

0x0000005d: TAG_formal_parameter [3]
                     AT_name( "line" )
                     AT_decl_file( "/Users/echristo/tmp/foo.c" )
                     AT_decl_line( 1 )
                     AT_type( {0x00000088} ( int ) )
                     AT_location( fbreg -20 )

0x0000006b: NULL

with current clang.

Thus far, I've spotted the problem _only_ with this particular function in this
particular source file.

Thank you.

Thus far, I've spotted the problem _only_ with this particular function in this
particular source file.

Fun. Only happens during optimization.

Please go ahead and file a bug. It'll probably be a dup of something
off of PR14330, but it'll be good to have.

Simple command line:

ghostwheel:~/tmp> ~/builds/build-llvm/Debug+Asserts/bin/clang -g -c
kern_sx.i -target x86_64-freebsd -O

-eric

Did we end up with a bug for this? (please mention the bug here - or,
if you believe it's PR14330, attach your test case to that bug so we
can ensure we verify it before closing the bug)

We did but it didn’t seem like a duplicate per se. It was pr15662 and I cc’d you on it at the time. :slight_smile:

-eric

Did we end up with a bug for this? (please mention the bug here - or,
if you believe it’s PR14330, attach your test case to that bug so we
can ensure we verify it before closing the bug)

Yeah, figured I’d get to it in the bug backlog, but helpful to have the PR number mentioned here on this thread.

Thanks,

  • David