<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ld cannot find crtbegin.o Amazon AMI, ignores -L/path/.../"
   href="https://bugs.llvm.org/show_bug.cgi?id=35992">35992</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ld cannot find crtbegin.o Amazon AMI, ignores -L/path/.../
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>omarsa@seas.upenn.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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:

<span class="quote">> strace -f clang test.c -o test 2>&1 | grep "crtbegin.o"</span >
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:
<span class="quote">> 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/</span >


This fixed all my issues.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>