Adding Ubuntu 32-bit support

Hello!

I'm trying to build Swift from source on a 32-bit Ubuntu virtual machine.
I've done minor modifications, mostly to the build script (see https://pastebin.com/rmWecTu7 )

I'm getting the following error, related to converting Float80 (see https://pastebin.com/ue8MRquU for full output)

1. While running pass #147 SILFunctionTransform "SIL alloc_stack Hoisting" on SILFunction "@_T0s7Float80V15_representationAB01_A14RepresentationVvg".
for getter for _representation at /home/gigi/local/Source/apple/swift/stdlib/public/core/FloatingPointTypes.swift.gyb:342:16
2. While converting type 'Float80' (declared at [/home/gigi/local/Source/apple/swift/stdlib/public/core/FloatingPointTypes.swift.gyb:74:8 - line:3662:1] RangeText="struct Float80 {

Using ~/local/Source/apple/swift/utils/build-script --release to build.

Please advise.

If I remember correctly, Float80 is also unimplemented in 32-bit arm. I would suggest adding a conditional compilation block to disable this code for 32-bit. I'm not that familiar with gyb, however, so I don't know what that looks like.

Cheers,
- Will

···

On Nov 27, 2017, at 1:08 AM, Ionel Lescai via swift-dev <swift-dev@swift.org> wrote:

Hello!

I'm trying to build Swift from source on a 32-bit Ubuntu virtual machine.
I've done minor modifications, mostly to the build script (see https://pastebin.com/rmWecTu7)

I'm getting the following error, related to converting Float80 (see https://pastebin.com/ue8MRquU for full output)

1. While running pass #147 SILFunctionTransform "SIL alloc_stack Hoisting" on SILFunction "@_T0s7Float80V15_representationAB01_A14RepresentationVvg".
for getter for _representation at /home/gigi/local/Source/apple/swift/stdlib/public/core/FloatingPointTypes.swift.gyb:342:16
2. While converting type 'Float80' (declared at [/home/gigi/local/Source/apple/swift/stdlib/public/core/FloatingPointTypes.swift.gyb:74:8 - line:3662:1] RangeText="struct Float80 {

Using ~/local/Source/apple/swift/utils/build-script --release to build.

Please advise.

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Disabled Float80, but I’m now getting a linker error:
undefined reference to ‘__mulodi4’

That function is defined in compiler-rt. Would linking to it solve the issue ?

In build_script_impl
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
)

Both these flags are being set to 1 – does that mean the swift compiler is being linked with compiler-rt ?

Found [SR-40] Port Swift to Arm progress / question
https://github.com/nwellnhof/swift/commit/1a5962c890e43f115fc5d629a7b2ec108e1f489a#diff-58073e2ae1d7149ac7f3fe3d32dff142

After adding __mulodi4 to stdlib/public/stubs/Stubs.cpp build fails to configure libdispatch:

cmark: using gold linker
+ /usr/bin/cmake --build /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/cmark-linux-i686 -- -j1 all
ninja: no work to do.
llvm: using gold linker
symlinking the system headers (/usr/include/c++) into the local clang build directory (/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/llvm-linux-i686/include).
+ ln -s -f /usr/include/c++ /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/llvm-linux-i686/include
+ /usr/bin/cmake --build /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/llvm-linux-i686 -- -j1 all
ninja: no work to do.
swift: using gold linker
+ /usr/bin/cmake --build /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686 -- -j1 all swift-test-stdlib-linux-i686
[1/52] Performing configure step for 'libdispatch'
FAILED: tools/SourceKit/libdispatch-prefix/src/libdispatch-stamp/libdispatch-configure 
cd /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686 && /usr/bin/cmake -DCMAKE_C_COMPILER=/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/llvm-linux-i686/bin/clang -DCMAKE_CXX_COMPILER=/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/llvm-linux-i686/bin/clang++ -DCMAKE_MAKE_PROGRAM=/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/ninja-build/ninja -DCMAKE_SWIFT_COMPILER=/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/bin/swiftc -DCMAKE_INSTALL_PREFIX=/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/tools/SourceKit/libdispatch-prefix -DENABLE_SWIFT=YES -GNinja /home/gigi/local/Source/apple/swift-corelibs-libdispatch && /usr/bin/cmake -E touch /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/tools/SourceKit/libdispatch-prefix/src/libdispatch-stamp/libdispatch-configure
CMake Error at CMakeLists.txt:237 (message):
  dtrace not found but explicitly requested


-- Configuring incomplete, errors occurred!
See also "/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686/CMakeFiles/CMakeOutput.log".
See also "/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686/CMakeFiles/CMakeError.log".
ninja: build stopped: subcommand failed.
/home/gigi/local/Source/apple/swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

Found Libdispatch on Linux, or C++ std::async? but don’t know if it’s related

EDIT: fixed by installing dtrace

Now getting linker error related to __mulodi4 in libdispatch.so … Guess I’ll have to add it somewhere here too…

EDIT:
After adding __mulodi4 to swift-corelibs-libdispatch/src/shims.c I am now getting:

[0/1] Re-running CMake...
-- Looking for arc4random
-- Looking for arc4random - not found
-- Looking for CLOCK_MONOTONIC_COARSE
-- Looking for CLOCK_MONOTONIC_COARSE - found
-- Looking for __printflike
-- Looking for __printflike - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686
[1/78] Building C object CMakeFiles/BlocksRuntime.dir/src/BlocksRuntime/data.c.o
[2/78] Generating /home/gigi/local/Source/apple/swift-corelibs-libdispatch/dispatch/module.modulemap, /home/gigi/local/Source/apple/swift-corelibs-libdispatch/private/module.modulemap
[3/78] Building C object CMakeFiles/BlocksRuntime.dir/src/BlocksRuntime/runtime.c.o
[4/78] Linking C static library libBlocksRuntime.a
[5/78] Building C object tests/CMakeFiles/bsdtests.dir/bsdtests.c.o
[6/78] Building C object tests/CMakeFiles/bsdtests.dir/dispatch_test.c.o
[7/78] Linking C static library tests/libbsdtests.a
[8/78] Generating swiftDispatch.o, swift/Dispatch.swiftmodule, swift/Dispatch.swiftdoc
FAILED: src/swiftDispatch.o src/swift/Dispatch.swiftmodule src/swift/Dispatch.swiftdoc 
cd /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686/src && /usr/bin/cmake -E make_directory /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686/src/swift && /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/bin/swiftc -emit-library -module-name Dispatch -module-link-name dispatch -emit-module-path /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686/src/swift/Dispatch.swiftmodule -I /home/gigi/local/Source/apple/swift-corelibs-libdispatch -I/usr/include -Xcc -fblocks -Xcc -fmodule-map-file=/home/gigi/local/Source/apple/swift-corelibs-libdispatch/dispatch/module.modulemap -force-single-frontend-invocation -c /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Block.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Data.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Dispatch.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/IO.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Private.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Queue.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Source.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Time.swift /home/gigi/local/Source/apple/swift-corelibs-libdispatch/src/swift/Wrapper.swift -o /home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/libdispatch-linux-i686/src/swiftDispatch.o
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "DispatchOverlayShims.h"
         ^
/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/lib/swift/shims/DispatchOverlayShims.h:16:1: error: expected identifier or '('
@import Dispatch;
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "DispatchOverlayShims.h"
         ^
/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/lib/swift/shims/DispatchOverlayShims.h:28:9: error: unknown type name 'id'
typedef id __swift_shims_dispatch_data_t;
        ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "DispatchOverlayShims.h"
         ^
/home/gigi/local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/lib/swift/shims/DispatchOverlayShims.h:31:15: error: unknown type name 'dispatch_queue_attr_t'
static inline dispatch_queue_attr_t
         ...

The function that calls ‘__mulodi4` is in compiler-rt, or the implementation is?

__mulodi4 is implemented in compiler-rt – don’t know why they aren’t used or why compiler-rt isn’t linked with the compiler.

As suggested in the post mentioned, I copied the implementation in Stubs.cpp.
I also had to copy it in Shims.c to solve the issue in libdispatch – don’t think it’s the best solution to duplicate the code everywhere, but I don’t know of a better solution atm.

And now I’m getting the last error related to DispatchOverlayShims.h

We ought to link the runtime against the fresh-built compiler_rt, if we aren’t already.

gigi@gigi-VirtualBox:~$ arch
i686
gigi@gigi-VirtualBox:~$ uname -a
Linux gigi-VirtualBox 4.13.0-36-generic #40~16.04.1-Ubuntu SMP Fri Feb 16 23:26:51 UTC 2018 i686 i686 i686 GNU/Linux
gigi@gigi-VirtualBox:~$ local/Source/apple/build/Ninja-ReleaseAssert/swift-linux-i686/bin/swiftc hello.swift 
gigi@gigi-VirtualBox:~$ ./hello 
Hello, Swift!
gigi@gigi-VirtualBox:~$ 

Works! 🎉

apple/swift repo from December 22, and libdispatch repo from today, but I guess I can do some clean up and make a PR.

@Joe_Groff How should I link compiler-rt ? I’m guessing it’s done in CMakeLists.txt. Should I also link it in libdispatch? Would there be any implications to doing this? Also what’s the difference between apple/swift-compiler-rt and the one already in llvm ?