<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Thanks for the help! I feel like I’m getting quite a bit closer with only a little bit of hacking.<div><br></div><div>This is now how I’m configuring LLVM/clang/lld master as of earlier this afternoon, it builds just fine (using clang 9 from the web site on Ubuntu 19.04):<div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">in $LLVM/build</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">$ cmake \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -G Ninja \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        "${PROJECT_DIR}/llvm-project/llvm" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DCMAKE_INSTALL_PREFIX="/opt/llvm-mips" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DLLVM_DEFAULT_TARGET_TRIPLE="mips-sgi-irix" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld;libunwind" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DLLVM_TARGETS_TO_BUILD="Mips" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DCLANG_DEFAULT_OBJCOPY="llvm-objcopy" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DCLANG_DEFAULT_LINKER="lld" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DCLANG_DEFAULT_RTLIB="compiler-rt" \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">        -DCLANG_DEFAULT_UNWINDLIB="libunwind"</span></font></div></div></blockquote><div><br></div><div>(Incidentally, I found a single use of CLANG_DEFAULT_RTLIBS in the CMake files, I assumed it shouldn’t be plural  since there were no other uses, so I fixed it locally.)</div><div><br></div><div>I also set up a new Irix toolchain which has required only tiny initial modifications:</div><div><ul><li>Cloned Driver/ToolChains/MipsLinux.{cpp,h} to Irix.{cpp,h}, renaming the class to just Irix (yeah it should be based on Generic_ELF but this was expedient)</li><ul><li>Added an override of getDefaultLinker() to return “ld.lld”</li></ul><li>Added target triple resolution for the new Irix toolchain to Basic/Targets.cpp</li><li>Cloned SolarisTargetInfo to IrixTargetInfo in Basic/Targets/OSTargets.h</li><ul><li>Adding __sgi as a predefined macro to it</li></ul><li>Made Driver.cpp instantiate the toolchain for an Irix target triple</li><li>Added ToolChains/MipsLinux.cpp to Driver/CMakeLists.txt</li></ul></div><div><div><br></div><div>All of this lets me compile for Irix using a command like the following:</div></div><div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">in $LLVM/build</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">$ ./bin/clang -g -D_LANGUAGE_C=1 \</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    -D__sgi=1 -D_SGIAPI=1 -D_SGI_SOURCE=1 -D_MIPSABI_SOURCE=1 \</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    --target=mips-sgi-irix march=mips4 -m64 -isysroot $IRIXSDK \</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    -c ../test/hello.c</span></font></div></blockquote><div><br></div><div>The .o this produces is recognized reasonably by <font face="Courier"><span style="font-style: normal; font-size: 14px;">file</span></font>:</div><div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">in $LLVM/build</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">$ file hello.</span></font></div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">hello.o: ELF 64-bit MSB relocatable, MIPS, MIPS-IV version 1 (SYSV), with debug_info, not stripped</span></font></div></blockquote><div><br></div><div>Unfortunately actually trying to produce an executable doesn’t work so well yet. It does use lld, but it tries to resolve a symbol inside the Irix libc.so which will actually be filled in by the runtime loader (<font face="Courier"><span style="font-style: normal; font-size: 14px;">rld</span></font>). This combined compilation and linking line:</div><div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">in $LLVM/build</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">$ bin/clang -v -Wl,-t -Wl,--verbose \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    -nostdlib -g -D_LANGUAGE_C=1 \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    -D__sgi=1 -D_SGIAPI=1 -D_SGI_SOURCE=1 -D_MIPSABI_SOURCE=1 \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    --target=mips-sgi-irix -march=mips4 -m64 -isysroot $IRIXSDK \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    $IRIXSDK/usr/lib64/mips4/libc.so \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    $IRIXSDK/usr/lib64/mips4/crt1.o \</span></font></div></div><div><div><font face="Courier"><span style="font-style: normal; font-size: 14px;">    -o hello ../test/hello.c</span></font></div></div></blockquote><div><br></div><div>produces this output (lightly edited for clarity, i.e. trimming paths to $LLVM and $IRIXSDK):</div><div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">clang version 10.0.0 (llvm-project.git f67aec686b01518c5cf9842ad22d7113b2d50955)</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">Target: mips64-sgi-irix</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">Thread model: posix</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">InstalledDir: $LLVM/build/./bin</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;"> "$LLVM/build/llvm/bin/clang-10" -cc1 -triple mips64-sgi-irix -emit-obj -mrelax-all -disable-free -main-file-name hello.c -mrelocation-model pic -pic-level 1 -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -target-cpu mips4 -target-feature -noabicalls -target-abi n64 -mfloat-abi hard -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v -resource-dir $LLVM/build/llvm/lib/clang/10.0.0 -isysroot $IRIXSDK -D _LANGUAGE_C=1 -D __sgi=1 -D _SGIAPI=1 -D _SGI_SOURCE=1 -D _MIPSABI_SOURCE=1 -internal-isystem $LLVM/build/llvm/lib/clang/10.0.0/include -fdebug-compilation-dir $LLVM/build -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -faddrsig -o /tmp/hello-190bff.o -x c ../test/hello.c</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">clang -cc1 version 10.0.0 based upon LLVM 10.0.0svn default target mips-sgi-irix</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ignoring nonexistent directory "$IRIXSDK/usr/local/include"</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ignoring duplicate directory "$LLVM/build/llvm/lib/clang/10.0.0/include"</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">#include "..." search starts here:</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">#include <...> search starts here:</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;"> $LLVM/build/llvm/lib/clang/10.0.0/include</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;"> $IRIXSDK/usr/include</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">End of search list.</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;"> "$LLVM/build/./bin/ld.lld" -z relro --eh-frame-hdr -m elf64btsmip -dynamic-linker /lib64/ld.so.1 -o hello -L/usr/lib64 -t --verbose $IRIXSDK/usr/lib64/mips4/libc.so $IRIXSDK/usr/lib64/mips4/crt1.o /tmp/hello-190bff.o</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: $IRIXSDK/usr/lib64/mips4/crt1.o</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: /tmp/hello-190bff.o</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">$IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.data' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.got' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.sbss' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.srdata' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.sdata' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.lit8' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.lit4' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: warning: found local symbol '.bss' in global part of symbol table in file $IRIXSDK/usr/lib64/mips4/libc.so</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">$IRIXSDK/usr/lib64/mips4/crt1.o</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">/tmp/hello-190bff.o</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">ld.lld: error: $IRIXSDK/usr/lib64/mips4/libc.so: undefined reference to _rld_new_interface</span></font></p></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal;"><font face="Courier" size="2"><span style="font-style: normal;">clang-10: error: linker command failed with exit code 1 (use -v to see invocation)</span></font></p></div></blockquote><div><br></div><div>Why is clang cc1 saying $IRIXSDK/usr/include doesn’t exist, when it actually does? (Just to reiterate, I’m using $IRIXSDK in this email for concision, it actually gives the full path—which “ls” lists the contents of just fine.)</div><div><br></div><div>Why is lld trying to resolve an undefined reference within a shared library, and what can I do about it? (The _rld_new_interface symbol is filled in by rld when it loads libc, there’s no need for it to be resolved against anything.) I’m not super familiar with ELF unlike Mach-O so I’m kind of surprised by this.</div><div><br></div><div>Is it related to the warnings about local symbols in global parts of the symbol table in libc.so? Is there any way to suppress those too, or to have lld interpret them “properly” (as SGI intended in Irix 6.5.30, irrespective of what’s proper today)?</div><div><br></div><div>  — Chris</div><div><br></div></div></body></html>