Dwarf symbols in XCode-built projects have wrong compilation dir

Originator:rsleevi
Number:rdar://13031540 Date Originated:17-Jan-2013 01:23 AM
Status:Open Resolved:
Product:Developer Tools Product Version:4.5.1
Classification:Serious Bug Reproducible:Always
 
17-Jan-2013 01:23 AM Ryan Sleevi:
Summary:
When building with XCode, the DW_at_comp_dir DIE for DW_tag_compile_units is inappropriately set to the CWD of XCode, rather than the CWD of the compilation command.

Steps to Reproduce:
1) Extract attached tar.bz2 file, which contains two XCode projects to demonstrate the issue
2) In a terminal, run the following commands:
  3) cd xcode-bug/dummy/dir1/dir2
  4) open ../../../dummy2/dir3/dummy2.xcodeproj
5) In XCode, compile
6) Navigate to the build results, and view the compilation steps. You should see something like:

"""
cd {some_path}/dummy2/dir3
setenv en_US.US-ASCII
{some long build command} -o {base path to output}/xcode-bug/dummy2/dir3/DerivedData/dummy2/Build/Intermediates/dummy2.build/Debug/dummy2.build/Objects-normal/x86_64/main.o
"""

7) Run "dwarfdump --debug-info {base path to output}/xcode-bug/dummy2/dir3/DerivedData/dummy2/Build/Intermediates/dummy2.build/Debug/dummy2.build/Objects-normal/x86_64/main.o | grep comp" 

Expected Results:
0x0000000b: TAG_compile_unit [1] *
             AT_comp_dir( "{some_path}/dummy2/dir3" )

Actual Results:
0x0000000b: TAG_compile_unit [1] *
             AT_comp_dir( "{some_path}/dummy/dir1/dir2" )

Notes:

In particular, this makes symbolicating files based on their dSYM impossible, because this does not preserve the compilation of the original file. You can see how this can create trouble by running dwarfdump with --debug-line and grepping for include_directories. The relative include path ("dummy2/dir3/../include/foo/../bar/foo.h" ) is instead treated as ("dummy/dir1/dir2/../include/foo/../bar/foo.h")

This is because the file_names entry (foo.h) is relative to the include_directories entry of "../include/foo/../bar" (DWARF 3, 6.2.4, Section 11), which itself is relative to the compilation dir of the current compilation unit (DWARF 3, 6.2.4 Section 10).

Executing the build commands manually (mod setenv) shows that Clang is setting the proper DW_at_comp_dir, as shown in http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?annotate=164676

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!