[LLVMbugs] [Bug 15992] New: Clang emits wrong URI's in line section for linux binaries on windows host.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue May 14 02:29:27 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15992

            Bug ID: 15992
           Summary: Clang emits wrong URI's in line section for linux
                    binaries on windows host.
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andri.m.jonsson at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

When trying to build linux x86_64 binaries using clang on windows it emits
wrong/invalid paths in line section data in .debug_info section.

Basic test app:

#include <cmath>
#include <climits>
#include <cstdio>
#include <iostream>

int main(int argc, char** argv)
{
    // Fibonacci sequence
    unsigned long long fn_1 = 1;
    unsigned long long fn_2 = 0;
    unsigned long long fn = 0;
    for(unsigned int i = 0; i < 80; i++)
    {
        std::cout << fn << std::endl;
        fn_2=fn_1;
        fn_1=fn;
        fn=fn_1+fn_2;
    }
}

My CWD is D:\Projects\LinuxTestProject\LinuxTestProject 

Command to compile cpp file(verbose)...
D:\SDK\Linux_ENV\bin\clang++.exe -c -pipe -D_DEBUG -D_CONSOLE -D_LINUX64
-DA2_64BIT -D_GNU_SOURCE -D__x86_64__ -D_DEBUG -D_UNICODE -DUNICODE -iquote ./
-g -v -Wno-unused-value -std=c++11 -pthread -target x86_64-unknown-linux-gnu
--sysroot=D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot -o
../../temp/linux64/LinuxTestProject/LinuxTestProject/debug/LinuxTestProject.obj
LinuxTestProject.cpp
clang version 3.2 (tags/RELEASE_32/final 179269)
 Target : x86_64-unknown-linux-gnu
 Thread model : posix
"D:/SDK/Linux_ENV/bin/clang++.exe" -cc1 -triple x86_64-unknown-linux-gnu
-emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name
LinuxTestProject.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno
-masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array
-target-cpu x86-64 -momit-leaf-frame-pointer -v -g -coverage-file
"D:\\Projects\\LinuxTestProject\\LinuxTestProject\\../../temp/linux64/LinuxTestProject/LinuxTestProject/debug/LinuxTestProject.obj"
-resource-dir "D:/SDK/Linux_ENV/bin\\..\\lib\\clang\\3.2" -iquote ./ -D _DEBUG
-D _CONSOLE -D _LINUX64 -D A2_64BIT -D _GNU_SOURCE -D __x86_64__ -D _DEBUG -D
_UNICODE -D UNICODE -isysroot D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot
-fmodule-cache-path "E:\\Temp\\clang-module-cache" -internal-isystem
"D:\\SDK\\Linux_ENV\\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0"
-internal-isystem
"D:\\SDK\\Linux_ENV\\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/x86_64-unknown-linux-gnu"
-internal-isystem
"D:\\SDK\\Linux_ENV\\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/backward"
-internal-isystem
D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot/usr/local/include
-internal-isystem D:/SDK/Linux_ENV/bin/../lib/clang/3.2/include
-internal-externc-isystem
D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot/include
-internal-externc-isystem
D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot/usr/include -Wno-unused-value
-std=c++11 -fdeprecated-macro -ferror-limit 19 -fmessage-length 0 -pthread
-mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -o
../../temp/linux64/LinuxTestProject/LinuxTestProject/debug/LinuxTestProject.obj
-x c++ LinuxTestProject.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target i686-pc-win32
ignoring nonexistent directory
"D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot/usr/local/include"
ignoring nonexistent directory
"D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot/include"
#include "..." search starts here:
 .
#include <...> search starts here:

D:\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0

D:\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/x86_64-unknown-linux-gnu

D:\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/backward
 D:/SDK/Linux_ENV/bin/../lib/clang/3.2/include
 D:/SDK/Linux_ENV/x86_64-unknown-linux-gnu/sysroot/usr/include
End of search list.

...and command to link executeable...
D:\SDK\Linux_ENV\bin\clang++.exe  -o
D:\Projects\exe\linux64\LinuxTestProject\LinuxTestProject_d.elf -pthread
-target x86_64-unknown-linux-gnu
--sysroot=D:\SDK\Linux_ENV\x86_64-unknown-linux-gnu\sysroot
LinuxTestProject.obj

Go to my VM and run "dwarfdump -l LinuxTestProject_d.elf | grep uri"
<pc>        [row,col] NS BB ET PE EB IS= DI= uri: "filepath"
0x004007c0  [  74, 0] uri:
"D:\Projects\LinuxTestProject\LinuxTestProject/D:\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/iostream"
0x00400800  [ 621, 0] uri:
"D:\Projects\LinuxTestProject\LinuxTestProject/LinuxTestProject.cpp"
0x00400a50  [ 621, 0] uri:
"D:\Projects\LinuxTestProject\LinuxTestProject/D:\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/cmath"

>From this it seems clang cannot determine what is an absolute path on windows
and just naively concatenates the abs path to the current working directory,
the abs path to the clang bin dir and the relative include path.

Trying to invoke clang++.exe via a relative path from the current working
directory gives this debug info
sproing at linuxdev:/mnt/hgfs/D/Projects/exe/linux64/LinuxTestProject$ dwarfdump
-l LinuxTestProject_d.elf | grep uri
<pc>        [row,col] NS BB ET PE EB IS= DI= uri: "filepath"
0x004007c0  [  74, 0] uri:
"D:\Projects\LinuxTestProject\LinuxTestProject/D:\Projects\LinuxTestProject\LinuxTestProject\..\..\..\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/iostream"
0x00400800  [ 621, 0] uri:
"D:\Projects\LinuxTestProject\LinuxTestProject/LinuxTestProject.cpp"
0x00400a50  [ 621, 0] uri:
"D:\Projects\LinuxTestProject\LinuxTestProject/D:\Projects\LinuxTestProject\LinuxTestProject\..\..\..\SDK\Linux_ENV\bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include/c++/4.7.0/cmath"

Now things are a bit clearer, from this it seems that clang is in fact capable
of determining if a path is absolute or relative but somewhere does not check
that and just blindly prefixes the file path with an absolute path to the
current working directory, damaging the path it constructed correctly in the
first place.

If you have any questions do not hesitate to ask! 
Also, if you know roughly where this is in the clang source but don't have time
to look at it, just let me know and I can have a look myself. Clang is quite
big and new to me so currently I wouldn't even know where to begin looking for
this code.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130514/e3433594/attachment.html>


More information about the llvm-bugs mailing list