Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for i586 #4013

Closed
AlexanderZhirov opened this issue Jul 28, 2022 · 11 comments
Closed

Build for i586 #4013

AlexanderZhirov opened this issue Jul 28, 2022 · 11 comments

Comments

@AlexanderZhirov
Copy link

AlexanderZhirov commented Jul 28, 2022

I am faced with a problem about compiling a compiler ldc for processor Geode LX800.
The bottom line is that I have a processor on which I want to compile the program, is an i586 architecture.
The official documentation says that "... the core is a combination of Intel Pentium ® processor, AMD Athlon™ processor, and AMD Geode LX processor specific instructions." - this means that the processor architecture is < i686. And judging by the fact that Linux gives a description when calling uname:

# uname -m
i586

This suggests that the processor is CLEARLY i586. The problem is that I can't assemble the software I need for this processor, since it is automatically assembled for i686.
What have I done?
I built an ldc compiler on this machine:

# ldc2 --version
LDC - the LLVM D compiler (1.30.0-git-32f5a35):
  based on DMD v2.100.1 and LLVM 10.0.1
  built with DMD32 D Compiler v2.086.1
  Default target: i686-pc-linux-gnu
  Host CPU: geode
  http://dlang.org - http://wiki.dlang.org/LDC
  Registered Targets:
    x86    - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64

And when I try to compile the program through it, I create a binary file, but when I start it outputs Illegal instruction:

# ldc2 app.d
# ./app
Illegal instruction

Here's using the mcpu flag:

# ldc2 --mcpu=i586 app.d -v
binary    /mnt/disc/sdb/part1/program/ldc/1.30/install/bin/ldc2
version   1.30.0-git-32f5a35 (DMD v2.100.1, LLVM 10.0.1)
config    /mnt/disc/sdb/part1/program/ldc/1.30/install/etc/ldc2.conf (i686-pc-linux-gnu)
predefs   LDC all D_Version2 assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo X86 D_InlineAsm_X86 D_HardFloat LittleEndian D_PIC linux Posix CRuntime_Glibc CppRuntime_Gcc LDC_LLVM_1000
parse     app
importall app
import    object    (/root/usr/program/ldc/1.30/install/include/d/object.d)
import    core.attribute    (/root/usr/program/ldc/1.30/install/include/d/core/attribute.d)
import    ldc.attributes    (/root/usr/program/ldc/1.30/install/include/d/ldc/attributes.d)
import    core.internal.hash    (/root/usr/program/ldc/1.30/install/include/d/core/internal/hash.d)
import    core.internal.traits  (/root/usr/program/ldc/1.30/install/include/d/core/internal/traits.d)
import    core.internal.entrypoint  (/root/usr/program/ldc/1.30/install/include/d/core/internal/entrypoint.d)
import    core.internal.array.appending (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/appending.d)
import    core.internal.array.comparison    (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/comparison.d)
import    core.internal.array.equality  (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/equality.d)
import    core.internal.array.casting   (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/casting.d)
import    core.internal.array.concatenation (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/concatenation.d)
import    core.internal.array.construction  (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/construction.d)
import    core.internal.array.capacity  (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/capacity.d)
import    core.internal.dassert (/root/usr/program/ldc/1.30/install/include/d/core/internal/dassert.d)
import    core.atomic   (/root/usr/program/ldc/1.30/install/include/d/core/atomic.d)
import    core.internal.attributes  (/root/usr/program/ldc/1.30/install/include/d/core/internal/attributes.d)
import    core.internal.atomic  (/root/usr/program/ldc/1.30/install/include/d/core/internal/atomic.d)
import    ldc.intrinsics    (/root/usr/program/ldc/1.30/install/include/d/ldc/intrinsics.di)
import    core.internal.destruction (/root/usr/program/ldc/1.30/install/include/d/core/internal/destruction.d)
import    core.internal.moving  (/root/usr/program/ldc/1.30/install/include/d/core/internal/moving.d)
import    core.internal.postblit    (/root/usr/program/ldc/1.30/install/include/d/core/internal/postblit.d)
import    core.internal.switch_ (/root/usr/program/ldc/1.30/install/include/d/core/internal/switch_.d)
import    core.lifetime (/root/usr/program/ldc/1.30/install/include/d/core/lifetime.d)
import    core.builtins (/root/usr/program/ldc/1.30/install/include/d/core/builtins.d)
semantic  app
entry     main          app.d
semantic2 app
semantic3 app
import    std.stdio (/root/usr/program/ldc/1.30/install/include/d/std/stdio.d)
import    core.stdc.stddef  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/stddef.d)
import    std.algorithm.mutation    (/root/usr/program/ldc/1.30/install/include/d/std/algorithm/mutation.d)
import    std.traits    (/root/usr/program/ldc/1.30/install/include/d/std/traits.d)
import    std.meta  (/root/usr/program/ldc/1.30/install/include/d/std/meta.d)
import    std.range.primitives  (/root/usr/program/ldc/1.30/install/include/d/std/range/primitives.d)
import    std.typecons  (/root/usr/program/ldc/1.30/install/include/d/std/typecons.d)
import    std.format.spec   (/root/usr/program/ldc/1.30/install/include/d/std/format/spec.d)
import    std.format.write  (/root/usr/program/ldc/1.30/install/include/d/std/format/write.d)
import    std.format.internal.write (/root/usr/program/ldc/1.30/install/include/d/std/format/internal/write.d)
import    std.internal.attributes   (/root/usr/program/ldc/1.30/install/include/d/std/internal/attributes.d)
import    std.range (/root/usr/program/ldc/1.30/install/include/d/std/range/package.d)
import    std.array (/root/usr/program/ldc/1.30/install/include/d/std/array.d)
import    std.functional    (/root/usr/program/ldc/1.30/install/include/d/std/functional.d)
import    std.conv  (/root/usr/program/ldc/1.30/install/include/d/std/conv.d)
import    std.ascii (/root/usr/program/ldc/1.30/install/include/d/std/ascii.d)
import    std.range.interfaces  (/root/usr/program/ldc/1.30/install/include/d/std/range/interfaces.d)
import    core.stdc.stdio   (/root/usr/program/ldc/1.30/install/include/d/core/stdc/stdio.d)
import    core.stdc.stdint  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/stdint.d)
import    core.stdc.config  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/config.d)
import    core.stdc.signal  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/signal.d)
import    core.stdc.wchar_  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/wchar_.d)
import    core.stdc.stdarg  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/stdarg.d)
import    core.stdc.time    (/root/usr/program/ldc/1.30/install/include/d/core/stdc/time.d)
import    core.sys.posix.stdc.time  (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/stdc/time.d)
import    core.sys.posix.sys.types  (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/sys/types.d)
import    core.sys.posix.config (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/config.d)
import    core.sys.posix.stdio  (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/stdio.d)
import    std.exception (/root/usr/program/ldc/1.30/install/include/d/std/exception.d)
import    core.stdc.errno   (/root/usr/program/ldc/1.30/install/include/d/core/stdc/errno.d)
import    std.utf   (/root/usr/program/ldc/1.30/install/include/d/std/utf.d)
import    core.exception    (/root/usr/program/ldc/1.30/install/include/d/core/exception.d)
import    core.internal.string  (/root/usr/program/ldc/1.30/install/include/d/core/internal/string.d)
import    std.algorithm.comparison  (/root/usr/program/ldc/1.30/install/include/d/std/algorithm/comparison.d)
import    core.stdc.string  (/root/usr/program/ldc/1.30/install/include/d/core/stdc/string.d)
import    std.format    (/root/usr/program/ldc/1.30/install/include/d/std/format/package.d)
import    std.format.read   (/root/usr/program/ldc/1.30/install/include/d/std/format/read.d)
import    std.format.internal.read  (/root/usr/program/ldc/1.30/install/include/d/std/format/internal/read.d)
import    std.algorithm.searching   (/root/usr/program/ldc/1.30/install/include/d/std/algorithm/searching.d)
import    std.bitmanip  (/root/usr/program/ldc/1.30/install/include/d/std/bitmanip.d)
import    std.system    (/root/usr/program/ldc/1.30/install/include/d/std/system.d)
import    core.bitop    (/root/usr/program/ldc/1.30/install/include/d/core/bitop.d)
import    core.memory   (/root/usr/program/ldc/1.30/install/include/d/core/memory.d)
import    core.time (/root/usr/program/ldc/1.30/install/include/d/core/time.d)
import    core.sys.posix.time   (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/time.d)
import    core.sys.posix.signal (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/signal.d)
import    core.sys.posix.sys.time   (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/sys/time.d)
import    core.sys.posix.sys.select (/root/usr/program/ldc/1.30/install/include/d/core/sys/posix/sys/select.d)
import    core.sys.linux.sys.time   (/root/usr/program/ldc/1.30/install/include/d/core/sys/linux/sys/time.d)
import    core.sys.linux.config (/root/usr/program/ldc/1.30/install/include/d/core/sys/linux/config.d)
import    core.internal.array.utils (/root/usr/program/ldc/1.30/install/include/d/core/internal/array/utils.d)
import    core.checkedint   (/root/usr/program/ldc/1.30/install/include/d/core/checkedint.d)
import    std.string    (/root/usr/program/ldc/1.30/install/include/d/std/string.d)
import    std.uni   (/root/usr/program/ldc/1.30/install/include/d/std/uni/package.d)
import    std.internal.unicode_tables   (/root/usr/program/ldc/1.30/install/include/d/std/internal/unicode_tables.d)
import    core.internal.lifetime    (/root/usr/program/ldc/1.30/install/include/d/core/internal/lifetime.d)
import    std.format.internal.floats    (/root/usr/program/ldc/1.30/install/include/d/std/format/internal/floats.d)
import    std.math.operations   (/root/usr/program/ldc/1.30/install/include/d/std/math/operations.d)
import    std.math  (/root/usr/program/ldc/1.30/install/include/d/std/math/package.d)
import    std.math.algebraic    (/root/usr/program/ldc/1.30/install/include/d/std/math/algebraic.d)
import    core.math (/root/usr/program/ldc/1.30/install/include/d/core/math.d)
import    core.stdc.math    (/root/usr/program/ldc/1.30/install/include/d/core/stdc/math.d)
import    std.math.constants    (/root/usr/program/ldc/1.30/install/include/d/std/math/constants.d)
import    std.math.exponential  (/root/usr/program/ldc/1.30/install/include/d/std/math/exponential.d)
import    std.math.hardware (/root/usr/program/ldc/1.30/install/include/d/std/math/hardware.d)
import    core.stdc.fenv    (/root/usr/program/ldc/1.30/install/include/d/core/stdc/fenv.d)
import    core.cpuid    (/root/usr/program/ldc/1.30/install/include/d/core/cpuid.d)
import    std.math.remainder    (/root/usr/program/ldc/1.30/install/include/d/std/math/remainder.d)
import    std.math.rounding (/root/usr/program/ldc/1.30/install/include/d/std/math/rounding.d)
import    std.math.traits   (/root/usr/program/ldc/1.30/install/include/d/std/math/traits.d)
import    std.math.trigonometry (/root/usr/program/ldc/1.30/install/include/d/std/math/trigonometry.d)
import    std.internal.unicode_grapheme (/root/usr/program/ldc/1.30/install/include/d/std/internal/unicode_grapheme.d)
GC stats  0M used, 5M free, 5M total
code      app
/root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app -L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32

The GCC compiler is built on i686:

# cc --version
cc (GCC) 9.5.0

At first I thought that I needed to rebuild the GCC compiler for the i586 architecture. I downloaded GCC 9.5.0 and started the installation:

# cd source
# ./contrib/download_prerequisites
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.18.tar.bz2: OK
All prerequisites downloaded successfully.
# cd ..
# mkdir build && cd build
# ../source/config.sub i586-linux
i586-pc-linux-gnu
# ../source/configure --prefix=$PWD/../install_i586 --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++,d --target=i586-pc-linux-gnu --disable-multilib --with-multilib-list=m32
...
# make -j8
...

But during the installation process I got an error:

...
checking for suffix of object files... mv -f .deps/findcomp.Tpo .deps/findcomp.Plo
configure: error: in `/root/source/gcc/9.5.0/build/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
Makefile:14150: recipe for target 'configure-target-libgcc' failed
make[1]: *** [configure-target-libgcc] Error 1
make[1]: *** Waiting for unfinished jobs....
...

If I do it without a flag --target=i586-pc-linux-gnu, then everything is assembled without errors.

Even tried with such a flag separately, it still doesn't work:

# /root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app -L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc -ldrun
time-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32 -march=geode
# ./app
Illegal instruction

I also tried with i586 and pentium - the result is the same.

I'm at a dead end, please help, guys.

@JohanEngelen
Copy link
Member

This is perhaps due to the D runtime and stdlib being built for i686. You can build runtime and stdlib yourself using ldc-build-runtime, see: https://wiki.dlang.org/Building_LDC_runtime_libraries

@AlexanderZhirov
Copy link
Author

This is perhaps due to the D runtime and stdlib being built for i686. You can build runtime and stdlib yourself using ldc-build-runtime, see: https://wiki.dlang.org/Building_LDC_runtime_libraries

And how would it be more correct in my case to build libraries? I'm not really familiar with the necessary parameters to pass as flags.

@JohanEngelen
Copy link
Member

Can you try ldc2 --mcpu=i586 app.d -betterC with a very simple app.d source? (just main without anything, or with puts or something super simple). If that results in an executable that executes without illegal instruction, then I think you can fix it by building druntime/phobos yourself with the -mcpu flag, and replace LDC's libraries with the newly built ones.

@JohanEngelen
Copy link
Member

Something like: ldc-build-runtime --ninja --dFlags="-mcpu=i585" --cFlags="-mcpu=i585"

@AlexanderZhirov
Copy link
Author

Something like: ldc-build-runtime --ninja --dFlags="-mcpu=i585" --cFlags="-mcpu=i585"

# ldc-build-runtime --dFlags="-mcpu=i585" --cFlags="-mcpu=i585"
.: Creating build directory: ldc-build-runtime.tmp
.: Downloading LDC source archive: https://github.com/ldc-developers/ldc/releases/download/v1.30.0/ldc-1.30.0-src.zip
.: Invoking: cmake -DLDC_EXE_FULL=/root/source/ldc/1.30/install-ldc/bin/ldc2 -DDMDFE_MINOR_VERSION=100 -DDMDFE_PATCH_VERSION=1 -DD_EXTRA_FLAGS=-mcpu=i585 -DRT_CFLAGS=-mcpu=i585 /root/source/ldc/ldc-build-runtime/ldc-build-runtime.tmp/ldc-src/runtime
-- The C compiler identification is GNU 5.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- -- LDC runtime configuration:
-- --  - Building 32/64-bit libraries (MULTILIB): OFF
-- --  - Building shared libraries (BUILD_SHARED_LIBS): BOTH
-- --  - Building LTO libraries (BUILD_LTO_LIBS): OFF
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/source/ldc/ldc-build-runtime/ldc-build-runtime.tmp
.: Invoking: make all
[  0%] Generating objects/core/atomic.o, objects/core/attribute.o, objects/core/bitop.o, objects/core/builtins.o, objects/core/checkedint.o, objects/core/cpuid.o, objects/core/demangle.o, objects/core/exception.o, objects/core/gc/config.o, objects/core/gc/gcinterface.o, objects/core/gc/registry.o, objects/core/int128.o, objects/core/internal/abort.o, objects/core/internal/array/appending.o, objects/core/internal/array/capacity.o, objects/core/internal/array/casting.o, objects/core/internal/array/comparison.o, objects/core/internal/array/concatenation.o, objects/core/internal/array/construction.o, objects/core/internal/array/equality.o, objects/core/internal/array/operations.o, objects/core/internal/array/utils.o, objects/core/internal/atomic.o, objects/core/internal/attributes.o, objects/core/internal/backtrace/dwarf.o, objects/core/internal/backtrace/elf.o, objects/core/internal/backtrace/handler.o, objects/core/internal/backtrace/libunwind.o, objects/core/internal/backtrace/macho.o, objects/core/internal/backtrace/unwind.o, objects/core/internal/container/array.o, objects/core/internal/container/common.o, objects/core/internal/container/hashtab.o, objects/core/internal/container/treap.o, objects/core/internal/convert.o, objects/core/internal/dassert.o, objects/core/internal/destruction.o, objects/core/internal/elf/dl.o, objects/core/internal/elf/io.o, objects/core/internal/entrypoint.o, objects/core/internal/execinfo.o, objects/core/internal/gc/bits.o, objects/core/internal/gc/impl/conservative/gc.o, objects/core/internal/gc/impl/manual/gc.o, objects/core/internal/gc/impl/proto/gc.o, objects/core/internal/gc/os.o, objects/core/internal/gc/pooltable.o, objects/core/internal/gc/proxy.o, objects/core/internal/hash.o, objects/core/internal/lifetime.o, objects/core/internal/moving.o, objects/core/internal/parseoptions.o, objects/core/internal/postblit.o, objects/core/internal/qsort.o, objects/core/internal/spinlock.o, objects/core/internal/string.o, objects/core/internal/switch_.o, objects/core/internal/traits.o, objects/core/internal/utf.o, objects/core/internal/util/array.o, objects/core/internal/util/math.o, objects/core/internal/vararg/aarch64.o, objects/core/internal/vararg/sysv_x64.o, objects/core/lifetime.o, objects/core/math.o, objects/core/memory.o, objects/core/runtime.o, objects/core/simd.o, objects/core/stdc/assert_.o, objects/core/stdc/complex.o, objects/core/stdc/config.o, objects/core/stdc/ctype.o, objects/core/stdc/errno.o, objects/core/stdc/fenv.o, objects/core/stdc/float_.o, objects/core/stdc/inttypes.o, objects/core/stdc/limits.o, objects/core/stdc/locale.o, objects/core/stdc/math.o, objects/core/stdc/signal.o, objects/core/stdc/stdarg.o, objects/core/stdc/stddef.o, objects/core/stdc/stdint.o, objects/core/stdc/stdio.o, objects/core/stdc/stdlib.o, objects/core/stdc/string.o, objects/core/stdc/tgmath.o, objects/core/stdc/time.o, objects/core/stdc/wchar_.o, objects/core/stdc/wctype.o, objects/core/stdcpp/allocator.o, objects/core/stdcpp/array.o, objects/core/stdcpp/exception.o, objects/core/stdcpp/memory.o, objects/core/stdcpp/new_.o, objects/core/stdcpp/string.o, objects/core/stdcpp/string_view.o, objects/core/stdcpp/type_traits.o, objects/core/stdcpp/typeinfo.o, objects/core/stdcpp/utility.o, objects/core/stdcpp/vector.o, objects/core/stdcpp/xutility.o, objects/core/sync/barrier.o, objects/core/sync/condition.o, objects/core/sync/config.o, objects/core/sync/event.o, objects/core/sync/exception.o, objects/core/sync/mutex.o, objects/core/sync/rwmutex.o, objects/core/sync/semaphore.o, objects/core/thread/context.o, objects/core/thread/fiber.o, objects/core/thread/osthread.o, objects/core/thread/package.o, objects/core/thread/threadbase.o, objects/core/thread/threadgroup.o, objects/core/thread/types.o, objects/core/time.o, objects/core/vararg.o, objects/core/volatile.o, objects/ldc/asan.o, objects/ldc/attributes.o, objects/ldc/dcompute.o, objects/ldc/eh_msvc.o, objects/ldc/sanitizer_common.o, objects/ldc/sanitizers_optionally_linked.o, objects/object.o, objects/rt/aApply.o, objects/rt/aApplyR.o, objects/rt/aaA.o, objects/rt/adi.o, objects/rt/arrayassign.o, objects/rt/arraycat.o, objects/rt/cast_.o, objects/rt/config.o, objects/rt/cover.o, objects/rt/critical_.o, objects/rt/deh.o, objects/rt/deh_win64_posix.o, objects/rt/dmain2.o, objects/rt/dso.o, objects/rt/dwarfeh.o, objects/rt/ehalloc.o, objects/rt/invariant.o, objects/rt/lifetime.o, objects/rt/memory.o, objects/rt/minfo.o, objects/rt/monitor_.o, objects/rt/msvc.o, objects/rt/msvc_math.o, objects/rt/profilegc.o, objects/rt/sections.o, objects/rt/sections_android.o, objects/rt/sections_darwin_64.o, objects/rt/sections_elf_shared.o, objects/rt/sections_ldc.o, objects/rt/sections_win64.o, objects/rt/tlsgc.o, objects/rt/trace.o, objects/rt/tracegc.o, objects/rt/util/typeinfo.o, objects/rt/util/utility.o, objects/core/sys/posix/aio.o, objects/core/sys/posix/arpa/inet.o, objects/core/sys/posix/config.o, objects/core/sys/posix/dirent.o, objects/core/sys/posix/dlfcn.o, objects/core/sys/posix/fcntl.o, objects/core/sys/posix/grp.o, objects/core/sys/posix/iconv.o, objects/core/sys/posix/inttypes.o, objects/core/sys/posix/libgen.o, objects/core/sys/posix/locale.o, objects/core/sys/posix/mqueue.o, objects/core/sys/posix/net/if_.o, objects/core/sys/posix/netdb.o, objects/core/sys/posix/netinet/in_.o, objects/core/sys/posix/netinet/tcp.o, objects/core/sys/posix/poll.o, objects/core/sys/posix/pthread.o, objects/core/sys/posix/pwd.o, objects/core/sys/posix/sched.o, objects/core/sys/posix/semaphore.o, objects/core/sys/posix/setjmp.o, objects/core/sys/posix/signal.o, objects/core/sys/posix/spawn.o, objects/core/sys/posix/stdc/time.o, objects/core/sys/posix/stdio.o, objects/core/sys/posix/stdlib.o, objects/core/sys/posix/string.o, objects/core/sys/posix/strings.o, objects/core/sys/posix/sys/filio.o, objects/core/sys/posix/sys/ioccom.o, objects/core/sys/posix/sys/ioctl.o, objects/core/sys/posix/sys/ipc.o, objects/core/sys/posix/sys/mman.o, objects/core/sys/posix/sys/msg.o, objects/core/sys/posix/sys/resource.o, objects/core/sys/posix/sys/select.o, objects/core/sys/posix/sys/shm.o, objects/core/sys/posix/sys/socket.o, objects/core/sys/posix/sys/stat.o, objects/core/sys/posix/sys/statvfs.o, objects/core/sys/posix/sys/time.o, objects/core/sys/posix/sys/ttycom.o, objects/core/sys/posix/sys/types.o, objects/core/sys/posix/sys/uio.o, objects/core/sys/posix/sys/un.o, objects/core/sys/posix/sys/utsname.o, objects/core/sys/posix/sys/wait.o, objects/core/sys/posix/syslog.o, objects/core/sys/posix/termios.o, objects/core/sys/posix/time.o, objects/core/sys/posix/ucontext.o, objects/core/sys/posix/unistd.o, objects/core/sys/posix/utime.o, objects/core/sys/linux/config.o, objects/core/sys/linux/dlfcn.o, objects/core/sys/linux/elf.o, objects/core/sys/linux/epoll.o, objects/core/sys/linux/err.o, objects/core/sys/linux/errno.o, objects/core/sys/linux/execinfo.o, objects/core/sys/linux/fcntl.o, objects/core/sys/linux/fs.o, objects/core/sys/linux/ifaddrs.o, objects/core/sys/linux/io_uring.o, objects/core/sys/linux/link.o, objects/core/sys/linux/netinet/in_.o, objects/core/sys/linux/netinet/tcp.o, objects/core/sys/linux/perf_event.o, objects/core/sys/linux/sched.o, objects/core/sys/linux/stdio.o, objects/core/sys/linux/string.o, objects/core/sys/linux/sys/auxv.o, objects/core/sys/linux/sys/eventfd.o, objects/core/sys/linux/sys/file.o, objects/core/sys/linux/sys/inotify.o, objects/core/sys/linux/sys/mman.o, objects/core/sys/linux/sys/prctl.o, objects/core/sys/linux/sys/procfs.o, objects/core/sys/linux/sys/signalfd.o, objects/core/sys/linux/sys/socket.o, objects/core/sys/linux/sys/sysinfo.o, objects/core/sys/linux/sys/time.o, objects/core/sys/linux/sys/xattr.o, objects/core/sys/linux/termios.o, objects/core/sys/linux/time.o, objects/core/sys/linux/timerfd.o, objects/core/sys/linux/tipc.o, objects/core/sys/linux/unistd.o, objects/core/sys/bionic/err.o, objects/core/sys/bionic/fcntl.o, objects/core/sys/bionic/stdlib.o, objects/core/sys/bionic/string.o, objects/core/sys/bionic/unistd.o
'i585' is not a recognized processor for this target (ignoring processor)
'i585' is not a recognized processor for this target (ignoring processor)
'i585' is not a recognized processor for this target (ignoring processor)
'i585' is not a recognized processor for this target (ignoring processor)
'i585' is not a recognized processor for this target (ignoring processor)
'i585' is not a recognized processor for this target (ignoring processor)
 #0 0x0aca3e64 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaca3e64)
 #1 0x0aca3f2d PrintStackTraceSignalHandler(void*) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaca3f2d)
 #2 0x0aca1b29 llvm::sys::RunSignalHandlers() (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaca1b29)
 #3 0x0aca1c4f SignalHandler(int) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaca1c4f)
 #4 0xfffffffff7fcc560 (linux-gate.so.1+0x560)
 #5 0x093da50e llvm::X86GenRegisterInfo::getRegClassWeight(llvm::TargetRegisterClass const*) const (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x93da50e)
 #6 0x09c03a82 (anonymous namespace)::MachineLICMBase::calcRegisterCost(llvm::MachineInstr const*, bool, bool) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x9c03a82)
 #7 0x09c04e10 (anonymous namespace)::MachineLICMBase::UpdateRegPressure(llvm::MachineInstr const*, bool) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x9c04e10)
 #8 0x09c06fdc (anonymous namespace)::MachineLICMBase::HoistOutOfLoop(llvm::DomTreeNodeBase<llvm::MachineBasicBlock>*) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x9c06fdc)
 #9 0x09c0a9d7 (anonymous namespace)::MachineLICMBase::runOnMachineFunction(llvm::MachineFunction&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x9c0a9d7)
#10 0x09bf22bb llvm::MachineFunctionPass::runOnFunction(llvm::Function&) [clone .part.0] (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x9bf22bb)
#11 0x0aa06a90 llvm::FPPassManager::runOnFunction(llvm::Function&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaa06a90)
#12 0x0aa082dc llvm::FPPassManager::runOnModule(llvm::Module&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaa082dc)
#13 0x0aa086e3 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaa086e3)
#14 0x0aa089bf llvm::legacy::PassManager::run(llvm::Module&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xaa089bf)
#15 0x089df128 (anonymous namespace)::codegenModule(llvm::TargetMachine&, llvm::Module&, char const*, llvm::CodeGenFileType) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89df128)
#16 0x089dfea2 writeModule(llvm::Module*, char const*) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89dfea2)
#17 0x089dcbf9 ldc::CodeGenerator::writeAndFreeLLModule(char const*) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89dcbf9)
#18 0x089dcf5b ldc::CodeGenerator::emit(Module*) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89dcf5b)
#19 0x089a7bf3 codegenModules(Array<Module*>&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89a7bf3)
#20 0x087acd44 mars_mainBody(Param&, Array<char const*>&, Array<char const*>&) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x87acd44)
#21 0x089a95a9 cppmain() (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89a95a9)
#22 0x088c813b _Dmain (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x88c813b)
#23 0x0ace39a1 _D2rt6dmain212_d_run_main2UAAakPUQgZiZ6runAllMFZ9__lambda2MFZv (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xace39a1)
#24 0x0ace37da _D2rt6dmain212_d_run_main2UAAakPUQgZiZ7tryExecMFMDFZvZv (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xace37da)
#25 0x0ace3902 _D2rt6dmain212_d_run_main2UAAakPUQgZiZ6runAllMFZv (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xace3902)
#26 0x0ace37da _D2rt6dmain212_d_run_main2UAAakPUQgZiZ7tryExecMFMDFZvZv (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xace37da)
#27 0x0ace3733 _d_run_main2 (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xace3733)
#28 0x0ace353f _d_run_main (/root/source/ldc/1.30/install-ldc/bin/ldc2+0xace353f)
#29 0x089d8895 args::forwardToDruntime(int, char const**) (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x89d8895)
#30 0x0851889e main (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x851889e)
#31 0xfffffffff79bd597 __libc_start_main (/lib/libc.so.6+0x18597)
#32 0x08575e24 _start (/root/source/ldc/1.30/install-ldc/bin/ldc2+0x8575e24)
/bin/sh: line 1: 632005 Segmentation fault      (core dumped) /root/source/ldc/1.30/install-ldc/bin/ldc2 -c --output-o -conf= -w -de -preview=dip1000 -preview=dtorfields -preview=fieldwise -mcpu=i585 -O3 -release -I/root/source/ldc/ldc-build-runtime/ldc-build-runtime.tmp/ldc-src/runtime/druntime/src -od=/root/source/ldc/ldc-build-runtime/ldc-build-runtime.tmp/objects -op core/atomic.d core/attribute.d core/bitop.d core/builtins.d core/checkedint.d core/cpuid.d core/demangle.d core/exception.d core/gc/config.d core/gc/gcinterface.d core/gc/registry.d core/int128.d core/internal/abort.d core/internal/array/appending.d core/internal/array/capacity.d core/internal/array/casting.d core/internal/array/comparison.d core/internal/array/concatenation.d core/internal/array/construction.d core/internal/array/equality.d core/internal/array/operations.d core/internal/array/utils.d core/internal/atomic.d core/internal/attributes.d core/internal/backtrace/dwarf.d core/internal/backtrace/elf.d core/internal/backtrace/handler.d core/internal/backtrace/libunwind.d core/internal/backtrace/macho.d core/internal/backtrace/unwind.d core/internal/container/array.d core/internal/container/common.d core/internal/container/hashtab.d core/internal/container/treap.d core/internal/convert.d core/internal/dassert.d core/internal/destruction.d core/internal/elf/dl.d core/internal/elf/io.d core/internal/entrypoint.d core/internal/execinfo.d core/internal/gc/bits.d core/internal/gc/impl/conservative/gc.d core/internal/gc/impl/manual/gc.d core/internal/gc/impl/proto/gc.d core/internal/gc/os.d core/internal/gc/pooltable.d core/internal/gc/proxy.d core/internal/hash.d core/internal/lifetime.d core/internal/moving.d core/internal/parseoptions.d core/internal/postblit.d core/internal/qsort.d core/internal/spinlock.d core/internal/string.d core/internal/switch_.d core/internal/traits.d core/internal/utf.d core/internal/util/array.d core/internal/util/math.d core/internal/vararg/aarch64.d core/internal/vararg/sysv_x64.d core/lifetime.d core/math.d core/memory.d core/runtime.d core/simd.d core/stdc/assert_.d core/stdc/complex.d core/stdc/config.d core/stdc/ctype.d core/stdc/errno.d core/stdc/fenv.d core/stdc/float_.d core/stdc/inttypes.d core/stdc/limits.d core/stdc/locale.d core/stdc/math.d core/stdc/signal.d core/stdc/stdarg.d core/stdc/stddef.d core/stdc/stdint.d core/stdc/stdio.d core/stdc/stdlib.d core/stdc/string.d core/stdc/tgmath.d core/stdc/time.d core/stdc/wchar_.d core/stdc/wctype.d core/stdcpp/allocator.d core/stdcpp/array.d core/stdcpp/exception.d core/stdcpp/memory.d core/stdcpp/new_.d core/stdcpp/string.d core/stdcpp/string_view.d core/stdcpp/type_traits.d core/stdcpp/typeinfo.d core/stdcpp/utility.d core/stdcpp/vector.d core/stdcpp/xutility.d core/sync/barrier.d core/sync/condition.d core/sync/config.d core/sync/event.d core/sync/exception.d core/sync/mutex.d core/sync/rwmutex.d core/sync/semaphore.d core/thread/context.d core/thread/fiber.d core/thread/osthread.d core/thread/package.d core/thread/threadbase.d core/thread/threadgroup.d core/thread/types.d core/time.d core/vararg.d core/volatile.d ldc/asan.d ldc/attributes.d ldc/dcompute.d ldc/eh_msvc.d ldc/sanitizer_common.d ldc/sanitizers_optionally_linked.d object.d rt/aApply.d rt/aApplyR.d rt/aaA.d rt/adi.d rt/arrayassign.d rt/arraycat.d rt/cast_.d rt/config.d rt/cover.d rt/critical_.d rt/deh.d rt/deh_win64_posix.d rt/dmain2.d rt/dso.d rt/dwarfeh.d rt/ehalloc.d rt/invariant.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d rt/msvc.d rt/msvc_math.d rt/profilegc.d rt/sections.d rt/sections_android.d rt/sections_darwin_64.d rt/sections_elf_shared.d rt/sections_ldc.d rt/sections_win64.d rt/tlsgc.d rt/trace.d rt/tracegc.d rt/util/typeinfo.d rt/util/utility.d core/sys/posix/aio.d core/sys/posix/arpa/inet.d core/sys/posix/config.d core/sys/posix/dirent.d core/sys/posix/dlfcn.d core/sys/posix/fcntl.d core/sys/posix/grp.d core/sys/posix/iconv.d core/sys/posix/inttypes.d core/sys/posix/libgen.d core/sys/posix/locale.d core/sys/posix/mqueue.d core/sys/posix/net/if_.d core/sys/posix/netdb.d core/sys/posix/netinet/in_.d core/sys/posix/netinet/tcp.d core/sys/posix/poll.d core/sys/posix/pthread.d core/sys/posix/pwd.d core/sys/posix/sched.d core/sys/posix/semaphore.d core/sys/posix/setjmp.d core/sys/posix/signal.d core/sys/posix/spawn.d core/sys/posix/stdc/time.d core/sys/posix/stdio.d core/sys/posix/stdlib.d core/sys/posix/string.d core/sys/posix/strings.d core/sys/posix/sys/filio.d core/sys/posix/sys/ioccom.d core/sys/posix/sys/ioctl.d core/sys/posix/sys/ipc.d core/sys/posix/sys/mman.d core/sys/posix/sys/msg.d core/sys/posix/sys/resource.d core/sys/posix/sys/select.d core/sys/posix/sys/shm.d core/sys/posix/sys/socket.d core/sys/posix/sys/stat.d core/sys/posix/sys/statvfs.d core/sys/posix/sys/time.d core/sys/posix/sys/ttycom.d core/sys/posix/sys/types.d core/sys/posix/sys/uio.d core/sys/posix/sys/un.d core/sys/posix/sys/utsname.d core/sys/posix/sys/wait.d core/sys/posix/syslog.d core/sys/posix/termios.d core/sys/posix/time.d core/sys/posix/ucontext.d core/sys/posix/unistd.d core/sys/posix/utime.d core/sys/linux/config.d core/sys/linux/dlfcn.d core/sys/linux/elf.d core/sys/linux/epoll.d core/sys/linux/err.d core/sys/linux/errno.d core/sys/linux/execinfo.d core/sys/linux/fcntl.d core/sys/linux/fs.d core/sys/linux/ifaddrs.d core/sys/linux/io_uring.d core/sys/linux/link.d core/sys/linux/netinet/in_.d core/sys/linux/netinet/tcp.d core/sys/linux/perf_event.d core/sys/linux/sched.d core/sys/linux/stdio.d core/sys/linux/string.d core/sys/linux/sys/auxv.d core/sys/linux/sys/eventfd.d core/sys/linux/sys/file.d core/sys/linux/sys/inotify.d core/sys/linux/sys/mman.d core/sys/linux/sys/prctl.d core/sys/linux/sys/procfs.d core/sys/linux/sys/signalfd.d core/sys/linux/sys/socket.d core/sys/linux/sys/sysinfo.d core/sys/linux/sys/time.d core/sys/linux/sys/xattr.d core/sys/linux/termios.d core/sys/linux/time.d core/sys/linux/timerfd.d core/sys/linux/tipc.d core/sys/linux/unistd.d core/sys/bionic/err.d core/sys/bionic/fcntl.d core/sys/bionic/stdlib.d core/sys/bionic/string.d core/sys/bionic/unistd.d
CMakeFiles/druntime-ldc.dir/build.make:329: recipe for target 'objects/core/atomic.o' failed
make[2]: *** [objects/core/atomic.o] Error 139
CMakeFiles/Makefile2:119: recipe for target 'CMakeFiles/druntime-ldc.dir/all' failed
make[1]: *** [CMakeFiles/druntime-ldc.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
.: Error: command failed with status 2

@AlexanderZhirov
Copy link
Author

Sorry... i586 needed

@kinke
Copy link
Member

kinke commented Jul 29, 2022

Default target: i686-pc-linux-gnu

So your LLVM apparently defaults to i686. I'm not sure whether -mcpu=i586 is supposed to work as expected with that triple. Compiling on the box itself, -mtriple=i586-linux-gnu -mcpu=native should definitely work though, for a little -betterC program as suggested by Johan at least. And then compiling druntime/Phobos with those flags via ldc-build-runtime as mentioned, and using those libs then later for the full non-betterC program. If there's still an invalid instruction, I'd compile/link the program via -g -link-defaultlib-debug, so that running it in a debugger should reveal where the invalid instruction comes from.

@AlexanderZhirov
Copy link
Author

Yes, I did it!

I have an i686 host with a GCC 5.3.0 compiler. The build path is /root/source.

  1. Using GCC 5.3.0, I built GCC 9.5.0 in an i686 environment
mkdir /root/source/gcc && cd /root/source/gcc
wget https://ftp.mpi-inf.mpg.de/mirrors/gnu/mirror/gcc.gnu.org/pub/gcc/releases/gcc-9.5.0/gcc-9.5.0.tar.gz
tar xf gcc-9.5.0.tar.gz -C source
cd source
./contrib/download_prerequisites
mkdir /root/source/gcc/build && cd /root/source/gcc/build
../source/configure --prefix=$PWD/../install --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++
make -j16
make install
  1. Using GCC 9.5.0, I built LLVM 10.0.1 in an i686 environment
mkdir /root/source/llvm && cd /root/source/llvm
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/llvm-project-10.0.1.tar.xz
tar xf llvm-project-10.0.1.tar.xz -C source
mkdir /root/source/llvm/build && cd /root/source/llvm/build
export CC=/root/source/gcc/install/bin/gcc
export CXX=/root/source/gcc/gcc-install/bin/g++
cmake ../source -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/../install -DLLVM_TARGETS_TO_BUILD='X86' -DCOMPILER_RT_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF
make -j16
make install
  1. Downloaded the DMD 2.086.1 compiler (since this version runs on the Geode LX800 processor without any problems)
  2. Copied all this to an external HDD and connected it to my Geode LX800 i586
  3. Using GCC 9.5.0, LLVM 10.0.1 and DMD 2.086.1, I built LDC 2.100.1 on Geode LX800 i586
mkdir -p ~/ldc/build && cd ~/ldc
git clone --recursive https://github.com/ldc-developers/ldc.git source
cd build
export PATH=<PATH_TO_GCC_BIN>:$PATH
cmake ../source -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/../install -DLLVM_ROOT_DIR=<PATH_TO_LLVM_INSTALL> -DD_COMPILER=<PATH_TO_DMD_COMPILER_X32>
make
make install
  1. Then, through ldc-build-runtime, I rebuilt the libraries for i586
ldc-build-runtime --dFlags="-mcpu=i586" --cFlags="-march=i586"

When performing the actions, I may have connected the necessary paths to LD_LIBRARY_PATH (I don't remember 😄 ).

Now LDC with the flag -mcpu=i586 compiles the binaries I need at the output and the architecture fully supports them!

Thank you so much for your help!

@kinke
Copy link
Member

kinke commented Jul 29, 2022

Great, so -mcpu=i586 seems to be enough. [I'm a bit surprised that your i686 LLVM linked into the i586 LDC works.] Note that you can add that option as default switch in etc/ldc2.conf, so that you don't have to specify it all the time.

I guess compiling on that box is severely limited by CPU speed and available RAM. If you just want to cross-compile to that target, see https://wiki.dlang.org/Cross-compiling_with_LDC. You'll 'just' need an additional cross-gcc toolchain from your host to i586 (incl. all required C libs) to make cross-linking work.

@AlexanderZhirov
Copy link
Author

AlexanderZhirov commented Jul 29, 2022

I guess compiling on that box is severely limited by CPU speed and available RAM. If you just want to cross-compile to that target, see https://wiki.dlang.org/Cross-compiling_with_LDC. You'll 'just' need an additional cross-gcc toolchain from your host to i586 (incl. all required C libs) to make cross-linking work.

The problem is that I can't compile GCC, I always get this error:

...
checking for suffix of object files... mv -f .deps/findcomp.Tpo .deps/findcomp.Plo
configure: error: in `/root/source/gcc/9.5.0/build/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
Makefile:14150: recipe for target 'configure-target-libgcc' failed
make[1]: *** [configure-target-libgcc] Error 1
make[1]: *** Waiting for unfinished jobs....
...

I wrote about it in my very first post.

@kinke
Copy link
Member

kinke commented Jul 30, 2022

Let's close this then, this was never an LDC issue per se.

@kinke kinke closed this as completed Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants