• LLVM for m68k completed (but not merged)

    From John Paul Adrian Glaubitz@21:1/5 to All on Sun Jun 21 22:20:03 2020
    Hi!


    I just received the news that the m68k backend for LLVM has been finished [1].

    It has not been merged upstream yet (that will take some time), but it should be usable now. I'm currently test-building it on Debian/m68k and it would probably
    a good idea if more people give it a spin to help finding issues.

    One issue I found is that CycleTimer has not been implemented. A quick fix is to
    use the definition used by MIPS, i.e.:

    diff --git a/llvm/utils/benchmark/src/cycleclock.h b/llvm/utils/benchmark/src/cycleclock.h
    index 1b0f09359c9..88b7805faaf 100644
    --- a/llvm/utils/benchmark/src/cycleclock.h
    +++ b/llvm/utils/benchmark/src/cycleclock.h
    @@ -161,7 +161,7 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
    struct timeval tv;
    gettimeofday(&tv, nullptr);
    return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
    -#elif defined(__mips__)
    +#elif defined(__mips__) || defined(__m68k__)
    // mips apparently only allows rdtsc for superusers, so we fall
    // back to gettimeofday. It's possible clock_gettime would be better.
    struct timeval tv;

    Thanks,
    Adrian

    [1] https://github.com/M680x0/M680x0-mono-repo

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer - glaubitz@debian.org
    `. `' Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to John Paul Adrian Glaubitz on Tue Jun 23 17:40:01 2020
    Hi!

    On 6/21/20 10:12 PM, John Paul Adrian Glaubitz wrote:
    I just received the news that the m68k backend for LLVM has been finished [1].
    I have had a go at the code now and with some changes to clang, I can actually cross-compile "Hello World" in C now, cross-compile it with clang and get a working
    m68k executable [1].

    glaubitz@epyc:/tmp/llvm-build> ./bin/clang -target m68k-linux-gnu ~/hello.c -o hello.m68k
    glaubitz@epyc:/tmp/llvm-build> file hello.m68k
    hello.m68k: ELF 32-bit MSB executable, Motorola m68k, 68020, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, not stripped
    glaubitz@epyc:/tmp/llvm-build> cp -av hello.m68k /local_scratch/glaubitz/ 'hello.m68k' -> '/local_scratch/glaubitz/hello.m68k' glaubitz@epyc:/tmp/llvm-build> schroot -c sid-m68k-sbuild glaubitz@epyc:/tmp/llvm-build> uname -a
    Linux epyc 5.6.0-2-amd64 #1 SMP Debian 5.6.14-1 (2020-05-23) m68k GNU/Linux glaubitz@epyc:/tmp/llvm-build> /glaubitz/hello.m68k
    Hello World!
    glaubitz@epyc:/tmp/llvm-build>

    Adrian

    [1] https://github.com/M680x0/M680x0-mono-repo/pull/7

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer - glaubitz@debian.org
    `. `' Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Finn Thain@21:1/5 to John Paul Adrian Glaubitz on Wed Jun 24 03:20:01 2020
    On Tue, 23 Jun 2020, John Paul Adrian Glaubitz wrote:

    Hi!

    On 6/21/20 10:12 PM, John Paul Adrian Glaubitz wrote:

    I just received the news that the m68k backend for LLVM has been
    finished [1].

    I have had a go at the code now and with some changes to clang, I can actually cross-compile "Hello World" in C now, cross-compile it with
    clang and get a working m68k executable [1].

    glaubitz@epyc:/tmp/llvm-build> ./bin/clang -target m68k-linux-gnu ~/hello.c -o hello.m68k
    glaubitz@epyc:/tmp/llvm-build> file hello.m68k
    hello.m68k: ELF 32-bit MSB executable, Motorola m68k, 68020, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, not stripped
    glaubitz@epyc:/tmp/llvm-build> cp -av hello.m68k /local_scratch/glaubitz/ 'hello.m68k' -> '/local_scratch/glaubitz/hello.m68k' glaubitz@epyc:/tmp/llvm-build> schroot -c sid-m68k-sbuild glaubitz@epyc:/tmp/llvm-build> uname -a
    Linux epyc 5.6.0-2-amd64 #1 SMP Debian 5.6.14-1 (2020-05-23) m68k GNU/Linux glaubitz@epyc:/tmp/llvm-build> /glaubitz/hello.m68k
    Hello World!
    glaubitz@epyc:/tmp/llvm-build>

    Adrian

    [1] https://github.com/M680x0/M680x0-mono-repo/pull/7


    Very impressive! I imagine that creating an LLVM backend would be a
    massive undertaking.

    Does this backend bring any benefits compared with gcc? E.g. will it help
    gain support for other languages, like rust?

    Do you know if anyone has run the LLVM unit tests on Motorola silicon?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to Finn Thain on Wed Jun 24 09:50:01 2020
    Hi Finn!

    On 6/24/20 3:07 AM, Finn Thain wrote:
    Very impressive! I imagine that creating an LLVM backend would be a
    massive undertaking.

    Does this backend bring any benefits compared with gcc? E.g. will it help gain support for other languages, like rust?

    Yes, my primary goal was to be able to use Rust on m68k. I have already
    started on the Rust part [1]. And now I need an m68k expert to help
    with the ABI part [2].

    Do you know if anyone has run the LLVM unit tests on Motorola silicon?

    Not that I know of. I have successfully built LLVM natively on qemu-m68k, but clang currently doesn't work properly [3]. I have not looked into details yet why that doesn't work.

    Adrian

    [1] https://github.com/glaubitz/rust/tree/m68k-linux
    [2] https://github.com/glaubitz/rust/blob/m68k-linux/src/librustc_target/abi/call/m68k.rs
    [3] https://github.com/M680x0/M680x0-mono-repo/issues/10

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer - glaubitz@debian.org
    `. `' Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)