[llvm-bugs] [Bug 35992] New: ld cannot find crtbegin.o Amazon AMI, ignores -L/path/.../

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 17 13:34:52 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=35992

            Bug ID: 35992
           Summary: ld cannot find crtbegin.o Amazon AMI, ignores
                    -L/path/.../
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: omarsa at seas.upenn.edu
                CC: llvm-bugs at lists.llvm.org

I compiled from source LLVM 6.0 on an Amazon Linux AMI 2017.09.1.20171120
x86_64

When attempting to compile a trivial program:

clang test.c -o test

ld fails with the following output:

/usr/bin/ld: cannot find crtbegin.o: No such file or directory
clang-6.0: error: linker command failed with exit code 1 (use -v to see
invocation)


Doing a find for crtbegin.o yields:
$ sudo find / -name "crtbegin.o" | grep -v "llvm"
/usr/lib/gcc/x86_64-amazon-linux/7/crtbegin.o
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/32/crtbegin.o
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/crtbegin.o


Adding -L/usr/lib/gcc/x86_64-amazon-linux/7/ or
-L/usr/lib/gcc/x86_64-amazon-linux/4.8.5/ did not help.


Running in verbose mode I can see the exact place it fails:
 "/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/../lib64/crt1.o
/usr/lib/../lib64/crti.o crtbegin.o -L/usr/lib/gcc/x86_64-amazon-linux/4.8.5/
-L/opt/nvidia/cuda/lib64/ -L/lib/../lib64 -L/usr/lib/../lib64
-L/home/ec2-user/Programs/llvm6-build/bin/../lib -L/lib -L/usr/lib
/tmp/gaussian-5f5074.o -lcudart_static -ldl -lrt -lstdc++ -lm -lgcc_s -lgcc
-lpthread -lc -lgcc_s -lgcc crtend.o /usr/lib/../lib64/crtn.o
/usr/bin/ld: cannot find crtbegin.o: No such file or directory

It seems to ignore the two directories I passed in.

To fix it, I straced the paths that ld was checking:

> strace -f clang test.c -o test 2>&1 | grep "crtbegin.o"
access("/home/ec2-user/Programs/llvm6-build/lib/clang/6.0.0/crtbegin.o", F_OK)
= -1 ENOENT (No such file or directory)
access("/home/ec2-user/Programs/llvm6-build/lib/clang/6.0.0/lib/linux/crtbegin.o",
F_OK) = -1 ENOENT (No such file or directory)
access("/lib/../lib64/crtbegin.o", F_OK) = -1 ENOENT (No such file or
directory)
access("/usr/lib/../lib64/crtbegin.o", F_OK) = -1 ENOENT (No such file or
directory)
access("/home/ec2-user/Programs/llvm6-build/bin/../lib/crtbegin.o", F_OK) = -1
ENOENT (No such file or directory)
access("/lib/crtbegin.o", F_OK)         = -1 ENOENT (No such file or directory)
access("/usr/lib/crtbegin.o", F_OK)     = -1 ENOENT (No such file or directory)
[pid  6469] execve("/usr/bin/ld", ["/usr/bin/ld", "--eh-frame-hdr", "-m",
"elf_x86_64", "-dynamic-linker", "/lib64/ld-linux-x86-64.so.2", "-o", "test",
"/usr/lib/../lib64/crt1.o", "/usr/lib/../lib64/crti.o", "crtbegin.o",
"-L/lib/../lib64", "-L/usr/lib/../lib64",
"-L/home/ec2-user/Programs/llvm6-"..., "-L/lib", "-L/usr/lib", ...], [/* 14
vars */] <unfinished ...>
[pid  6469] open("crtbegin.o", O_RDONLY) = -1 ENOENT (No such file or
directory)
[pid  6469] write(2, "crtbegin.o", 10crtbegin.o)  = 10


I ended up creating symlinks to the folders where ld was looking:
> sudo ln -s /usr/lib/gcc/x86_64-amazon-linux/7/crtbegin.o /lib/../lib64/
> sudo ln -s /usr/lib/gcc/x86_64-amazon-linux/7/crtend.o  /lib/../lib64/


This fixed all my issues.

-- 
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/20180117/ba62d393/attachment-0001.html>


More information about the llvm-bugs mailing list