Build Fail on apple/llvm-project

Hi,

I'm not sure if this is the right forum to ask this question. But I take my chances anyways. I am trying to build the branch swif/tensorflow llvm repo. I am facing following issues.

I am building the toolchain on Linux Ubuntu 18.04 machine. (Build also fails on the mater please check the EDIT section of the post below)

Here are the steps I'm following as per the build instructions from the Readme.md file. I have installed all the dependencies as suggested before trying to compile the code.

git clone  https://github.com/apple/llvm-project.git
cd llvm-project
git checkout swift/tensorflow
mkdir build
cd build
cmake -G "Unix Makefiles" --DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" ../llvm
cmake -build .

I do face some errors regarding the -fpermissive

In file included from /home/gl-245/swift_stuff/cherry_pick_ex/my_llvm_fork/llvm-project/clang/lib/CrossTU/CrossTranslationUnit.cpp:18:0:
/home/gl-245/swift_stuff/cherry_pick_ex/my_llvm_fork/llvm-project/clang/include/clang/Frontend/CompilerInstance.h:196:48: error: declaration of ‘llvm::IntrusiveRefCntPtr<clang::InMemoryOutputFileSystem> clang::CompilerInstance::InMemoryOutputFileSystem’ [-fpermissive]
   IntrusiveRefCntPtr<InMemoryOutputFileSystem> InMemoryOutputFileSystem;
                                                ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/gl-245/swift_stuff/cherry_pick_ex/my_llvm_fork/llvm-project/clang/include/clang/Frontend/CompilerInstance.h:15:0,
                 from /home/gl-245/swift_stuff/cherry_pick_ex/my_llvm_fork/llvm-project/clang/lib/CrossTU/CrossTranslationUnit.cpp:18:
/home/gl-245/swift_stuff/cherry_pick_ex/my_llvm_fork/llvm-project/clang/include/clang/Basic/InMemoryOutputFileSystem.h:31:7: error: changes meaning of ‘InMemoryOutputFileSystem’ from ‘class clang::InMemoryOutputFileSystem’ [-fpermissive]
 class InMemoryOutputFileSystem : public llvm::vfs::FileSystem {
       ^~~~~~~~~~~~~~~~~~~~~~~~

I did fix this error by renaming the variable InMemoryOutputFileSystem to InMemoryOutputFileSystemVar (Just changed the name so that class and the variable names will not collide) In couple of places in where this variable is used.

	modified:   clang/include/clang/Frontend/CompilerInstance.h
	modified:   clang/lib/Frontend/CompilerInstance.cpp

After that build is passing the compilation stage. But I'm facing the linking errors. Not sure how to fix this linker error.

[ 85%] Linking CXX executable ../../../../bin/clang
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
tools/clang/tools/driver/CMakeFiles/clang.dir/build.make:335: recipe for target 'bin/clang-10' failed
make[2]: *** [bin/clang-10] Error 1
make[2]: *** Deleting file 'bin/clang-10'
CMakeFiles/Makefile2:33814: recipe for target 'tools/clang/tools/driver/CMakeFiles/clang.dir/all' failed
make[1]: *** [tools/clang/tools/driver/CMakeFiles/clang.dir/all] Error 2
Makefile:170: recipe for target 'all' failed
make: *** [all] Error 2

Any inputs on how to fix this error will be helpful.

EDIT:
I did checkout the apple/llvm-project and ran the same commands. Surprisingly I am getting the same error. This means the error is not specific to swift/tensorflow branch. But the apple/llvm-project master itself is failing in my case. Any inputs?

Just an update on the above problem. I did try to use ninja build to see if it has any improvements but no luck. Here are the list of commands I ran.

cmake -G "Ninja" --DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" ../llvm
ninja

Here is the error

/home/gl-245/swift_stuff/cherry_pick_ex/my_llvm_fork/llvm-project/clang/include/clang/Basic/PointerAuthOptions.h:76:39: warning: ‘clang::PointerAuthSchema::DiscriminationKind’ is too small to hold all values of ‘enum class clang::PointerAuthSchema::Discrimination’
   Discrimination DiscriminationKind : 2;
                                       ^
[3049/4174] Linking CXX executable bin/llvm-lto
ninja: build stopped: subcommand failed.

Is there any additional parameters we can pass to cmake and Nija to spit out some more error message to get some more clue?

I'm still stuck at the same point :frowning: Is there any nightly builds run for Linux targets which I could look for the current status?

Are you trying to build LLVM as a part of building Swift? Or do you want to contribute to Clang/LLVM and not to Swift?

Yes, I am trying to build the LLVM for swift. Specifically for swift for tensorflow branch. But When I try to run the build script, it is failing for the above mentioned reasons. So I am trying to build the apple/llvm-project in isolation to figure out what is going wrong.

I'm not sure about the master and tensorflow branches; the LLVM branch corresponding to Swift's master branch is called swift/master. Are you unable to build that? Can you share what configuration you are using (utils/update-checkout --dump-hashes).

Sure, Here it goes.

# utils/update-checkout --dump-hashes
{
    "https-clone-pattern": "https://github.com/%s.git", 
    "ssh-clone-pattern": "git@github.com:%s.git", 
    "repos": {
        "sourcekit-lsp": {
            "remote": {
                "id": "apple/sourcekit-lsp"
            }
        }, 
        "indexstore-db": {
            "remote": {
                "id": "apple/indexstore-db"
            }
        }, 
        "llbuild": {
            "remote": {
                "id": "apple/swift-llbuild"
            }
        }, 
        "swift-xcode-playground-support": {
            "remote": {
                "id": "apple/swift-xcode-playground-support"
            }
        }, 
        "swift-syntax": {
            "remote": {
                "id": "apple/swift-syntax"
            }
        }, 
        "swift-corelibs-xctest": {
            "remote": {
                "id": "apple/swift-corelibs-xctest"
            }
        }, 
        "swiftpm": {
            "remote": {
                "id": "apple/swift-package-manager"
            }
        }, 
        "swift-tools-support-core": {
            "remote": {
                "id": "apple/swift-tools-support-core"
            }
        }, 
        "cmake": {
            "platforms": [
                "Linux"
            ], 
            "remote": {
                "id": "KitWare/CMake"
            }
        }, 
        "swift-driver": {
            "remote": {
                "id": "apple/swift-driver"
            }
        }, 
        "tensorflow-swift-apis": {
            "remote": {
                "id": "tensorflow/swift-apis"
            }
        }, 
        "yams": {
            "remote": {
                "id": "asuhan/Yams"
            }
        }, 
        "tensorflow": {
            "remote": {
                "id": "tensorflow/tensorflow"
            }
        }, 
        "icu": {
            "platforms": [
                "Linux"
            ], 
            "remote": {
                "id": "unicode-org/icu"
            }
        }, 
        "swift-corelibs-foundation": {
            "remote": {
                "id": "apple/swift-corelibs-foundation"
            }
        }, 
        "llvm-project": {
            "remote": {
                "id": "apple/llvm-project"
            }
        }, 
        "swift-argument-parser": {
            "remote": {
                "id": "apple/swift-argument-parser"
            }
        }, 
        "ninja": {
            "remote": {
                "id": "ninja-build/ninja"
            }
        }, 
        "swift-integration-tests": {
            "remote": {
                "id": "apple/swift-integration-tests"
            }
        }, 
        "swift": {
            "remote": {
                "id": "apple/swift"
            }
        }, 
        "swift-stress-tester": {
            "remote": {
                "id": "apple/swift-stress-tester"
            }
        }, 
        "cmark": {
            "remote": {
                "id": "apple/swift-cmark"
            }
        }, 
        "swift-format": {
            "remote": {
                "id": "apple/swift-format"
            }
        }, 
        "swift-corelibs-libdispatch": {
            "remote": {
                "id": "apple/swift-corelibs-libdispatch"
            }
        }
    }, 
    "branch-schemes": {
        "repro": {
            "repos": {
                "sourcekit-lsp": "3366391746f1cb45fa87e082e51d1be0adb3e0f0", 
                "swift-syntax": "3fbed3ad7cdd185827e2c2459d3f4542e1656310", 
                "llbuild": "f409cbe6647a348d307f321a3b461fbf8277a4b2", 
                "swift-xcode-playground-support": "88043d7d320f92598efb39408c3f4b1903a4fff6", 
                "indexstore-db": "8c593c430c714aac7e777b501f26e8e36849315e", 
                "swift-corelibs-xctest": "fffe073707908e46338c37686d58f4b9f9a4520c", 
                "swiftpm": "a399011303243ceb35520563667775d1dce3c746", 
                "swift-tools-support-core": "25fc6eaec5d9f79b79419c5bdaa04e434cbcd568", 
                "cmake": "skip", 
                "swift-driver": "7a441561a176f6eac2953aea2c395cc4e683f820", 
                "tensorflow-swift-apis": "b719d997beca0f6ddb8576776ee917556cfc485c", 
                "yams": "8e986eb32365aec111fe6905719fadb61543ece1", 
                "tensorflow": "b36436b087bd8e8701ef51718179037cccdfc26e", 
                "icu": "fd123bf023882f07bfacf51c39111be2f946d8f8", 
                "swift-corelibs-foundation": "a1601ff3d75346a2e987c5cadf054c18fd90217c", 
                "llvm-project": "14a10d635b229fb3d8fc0d80340f98430b46fcff", 
                "swift-argument-parser": "15351c1cd009eba0b6e438bfef55ea9847a8dc4a", 
                "ninja": "a1f879b29c9aafe6a2bc0ba885701f8f4f19f772", 
                "swift-integration-tests": "11f0f6e8b34ba9782b5841dbeaa207d0b4620152", 
                "swift": "c08d0804e2e44acba1c86937f738114a0ba6b0e4", 
                "swift-stress-tester": "4d8f8a790d32a3ced310c6b68c46ca8e6f71f52c", 
                "cmark": "9c8096a23f44794bde297452d87c455fc4f76d42", 
                "swift-format": "d4bba6e22891ff1813e8267e36f2b00307684366", 
                "swift-corelibs-libdispatch": "f13ea5dcc055e5d2d7c02e90d8c9907ca9dc72e1"
            }, 
            "aliases": [
                "repro"
            ]
        }
    }
}

I am following the build instructions from here.

I've built Swift (tensorflow branch and master branch) on Ubuntu 18.04 a lot and never seen these errors.

Maybe you're running out of memory during linking? Googling "collect2: fatal error: ld terminated with signal 9" suggests that it means running out of memory.

Here's a nightly build on the tensorflow branch that has been passing: https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow/

Also you can find nightly logs from builds on the master branch at ci.swift.org.

I agree with @marcrasi, debug builds need a lot of memory, linking errors. Maybe you could try using less cores: -j x. You could also try building in Release instead.

@marcrasi and @augusto2112 thanks for your inputs. Will try your suggestions and get back with an update.

1 Like

Hi All,
I have some update now. Finally I was able to build the code. I did face some other issues I have further more questions on the same. Before that Lemme put the changes which I did to make it work in my system.

  1. I experimented with increasing the swap partition size a bit finally I need to increase it to 8GB for it to work. Here is the link which I followed to change the swap partition size.
  2. I carefully monitored the swap partition usage using linux top command. Which gave better insight on the CPU and memory utilization to fine tune the swap size.
  3. Reduced the number of core used by using -j options. I have to ramp it down all the way to 2 from 8.

These options got the build going.

Here are some more questions I have.

  1. I was using python-3 virtual environment to build. But It was failing because it was looking for references to python-2.
    Question: Is there a way for the build to look for Python-3 dependencies?
  2. I need to try this one yet, but just want to know if there is anything I need to be aware of. I am planning to add some custom patch on apple/llvm repo locally.
    Question: Should I need to build everything again? Or is there any way I can trigger the build script to build only the llvm portion of it from the script build-toolchain-tensorflow?

So far I didn't find any proper documentation on the possible options which we can give it to the build scripts. Any reference on the same will be really helpful.

I don't know much about what it uses python for, sorry.

You can do incremental builds in the build directory. See https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#incremental-builds-with-ninja . You can pass it paths to other things, like the llvm in your build directory, to make it rebuild those other things.

1 Like
Terms of Service

Privacy Policy

Cookie Policy