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

Please add ARM compiler RT library #97

Open
denizzzka opened this issue Feb 27, 2020 · 11 comments
Open

Please add ARM compiler RT library #97

denizzzka opened this issue Feb 27, 2020 · 11 comments

Comments

@denizzzka
Copy link

denizzzka commented Feb 27, 2020

Please add ARM compiler RT library to prevent linking errors while cross-compile. Errors like:

ld.lld: error: undefined symbol: __aeabi_uldivmod
@denizzzka
Copy link
Author

Strictly I could not verify it at 100% because built-in linker is not working for cross compiling ARM

void main()
{
    long a = 1;
    long b = 1;

    long c = a / b;
}
ldc2 --static --linker=lld -march=thumb -mcpu=cortex-m3 app.d
ld.lld: error: unknown argument: --no-warn-search-mismatch
collect2: error: ld returned 1 exit status

@denizzzka
Copy link
Author

All the same, anyway, an external linker has to take this library from somewhere.

@denizzzka denizzzka reopened this Feb 27, 2020
@WebDrake
Copy link
Contributor

Thanks for reporting this. Which version are you using? Can you give me the result of snap list ldc2 just to confirm?

@denizzzka
Copy link
Author

Name  Version  Rev  Tracking  Publisher  Notes
ldc2  1.18.0   115  stable    ldc        classic

@denizzzka
Copy link
Author

denizzzka commented Feb 29, 2020

Looks like it is need to add:

        -DCOMPILER_RT_BUILD_BUILTINS=ON \
        -DCOMPILER_RT_BAREMETAL_BUILD=ON \

into llvm section of snapcraft.yaml

it would also be cool to add libunwind because it is sort of runtime library for dlang without betterC

        -DLLVM_ENABLE_PROJECTS='compiler-rt;lld;libunwind' \

WebDrake added a commit to WebDrake/ldc2.snap that referenced this issue Feb 29, 2020
This should improve the cross-compiler support, for example if we want
to build for ARM.

Part of ldc-developers#97.
@WebDrake
Copy link
Contributor

WebDrake commented Mar 1, 2020

OK, so let's try and break this down following @kinke's feedback on #101.

Some of the reported errors appear to be unrelated to ARM and are instead about using LLD. I can reproduce with the following steps:

  • install lld from apt repos on my Ubuntu 18.04 system (this is LLD 6.0.0, as opposed to LLVM 9.0.1 built in the snap package)

  • try to build a simple hello.d using LLD as the linker:

    ldc2 --static --linker=lld hello.d

This results in the error:

/usr/bin/ld.lld: error: unknown argument: --no-warn-search-mismatch
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1

If I do not have lld installed on my host system, instead I get:

collect2: fatal error: cannot find 'ld'
compilation terminated.
Error: /usr/bin/gcc failed with status: 1

If instead I try to build with

ldc2 --static --link-internally hello.d

I get the errors:

lld: error: unknown argument '--no-warn-search-mismatch'
lld: error: unable to find library -lrt
lld: error: unable to find library -ldl
lld: error: unable to find library -lpthread
lld: error: unable to find library -lm
Error: linking with LLD failed

... which suggests that lld can be used per se, but the system libraries it requires/expects are missing from the snap package.

The --no-warn-search-mismatch flag is coming from ldc2.conf, and should not be used with LLD as it does not support it, see:
ldc-developers/ldc#2717 (comment)

The flag is used with the snap package, but not with the standard LDC binaries, to avoid linker errors when searching for paths that do not exist. Essentially it's a workaround for including all of lib, lib32 and lib64 in the search path. So we probably ought to address this separately.

That aside, it's clear we have (at least) 2 separate problems here:

  • how to ensure that the snap package can use LLD as the linker, reliably
  • how to ensure that the snap package supports cross-compiling to ARM (which might include relying on the host system having some support in place, rather than placing everything in the snap package itself)

A related question is how much the snap package should aim to fulfil that goal. For example: what is the current state of support provided by LDC binary packages?

@denizzzka are you able/willing to try using one of the LDC binary packages downloadable from GitHub (https://github.com/ldc-developers/ldc/releases/tag/v1.18.0 should give you a comparable setup) and compare how it works when trying to cross-compile, with and without using lld as the linker?

@denizzzka
Copy link
Author

Some of the reported errors appear to be unrelated to ARM and are instead about using LLD.

What kind of erros?

@WebDrake
Copy link
Contributor

WebDrake commented Mar 1, 2020

The unknown argument error reported in #97 (comment).

@kinke
Copy link
Member

kinke commented Mar 1, 2020

The lld arg has been resolved with v1.20...

@WebDrake
Copy link
Contributor

WebDrake commented Mar 1, 2020

On the more general problem: multi-arch cross-compiling support for snap packages is non-trivial in general. To see why, consider the following difference between the linking of 64-bit and 32-bit libs in the snap package:

64-bit:

$ ldd /snap/ldc2/current/lib64/libphobos2-ldc-shared.so
	linux-vdso.so.1 (0x00007ffd555da000)
	libgtk3-nocsd.so.0 => /usr/lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (0x00007f4a2b3e1000)
	libdruntime-ldc-shared.so.88 => /snap/ldc2/current/lib64/libdruntime-ldc-shared.so.88 (0x00007f4a2b078000)
	libm.so.6 => /snap/core/current/lib/x86_64-linux-gnu/libm.so.6 (0x00007f4a2ad6f000)
	libpthread.so.0 => /snap/core/current/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4a2ab52000)
	librt.so.1 => /snap/core/current/lib/x86_64-linux-gnu/librt.so.1 (0x00007f4a2a94a000)
	libdl.so.2 => /snap/core/current/lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4a2a746000)
	libgcc_s.so.1 => /snap/core/current/lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4a2a530000)
	libc.so.6 => /snap/core/current/lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a2a166000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4a2bd94000)

32-bit:

$ ldd /snap/ldc2/current/lib32/libphobos2-ldc-shared.so
ERROR: ld.so: object 'libgtk3-nocsd.so.0' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
	linux-gate.so.1 (0xf7f0c000)
	libdruntime-ldc-shared.so.88 => /snap/ldc2/current/lib32/libdruntime-ldc-shared.so.88 (0xf7834000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7732000)
	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xf7713000)
	librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xf7709000)
	libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xf7704000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf76e6000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf750a000)
	/lib/ld-linux.so.2 (0xf7f0d000)

This is almost certainly why the snap package (as currently written) reports some missing stage-packages during the build. This can in principle be addressed by the following diff:

diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index 0171f08..15b55cc 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -58,6 +58,13 @@ parts:
     - g++-multilib
     - ninja-build
     - zlib1g-dev
+    stage-packages:
+    - on amd64:
+      - lib32gcc1
+      - libc6-i386
+    - on i386:
+      - lib64gcc1
+      - libc6-amd64
     after:
     - ctest-setup
     - ldc-bootstrap

... after which the 32-bit libs link up against those staged packages instead:

$ ldd /snap/ldc2/current/lib32/libphobos2-ldc-shared.so
ERROR: ld.so: object 'libgtk3-nocsd.so.0' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
	linux-gate.so.1 (0xf7fc3000)
	libdruntime-ldc-shared.so.88 => /snap/ldc2/current/lib32/libdruntime-ldc-shared.so.88 (0xf78eb000)
	libm.so.6 => /snap/ldc2/current/lib32/libm.so.6 (0xf7896000)
	libpthread.so.0 => /snap/ldc2/current/lib32/libpthread.so.0 (0xf77ab000)
	librt.so.1 => /snap/ldc2/current/lib32/librt.so.1 (0xf77a2000)
	libdl.so.2 => /snap/ldc2/current/lib32/libdl.so.2 (0xf779d000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf777f000)
	libc.so.6 => /snap/ldc2/current/lib32/libc.so.6 (0xf75ca000)
	/lib/ld-linux.so.2 (0xf7fc4000)

@WebDrake
Copy link
Contributor

WebDrake commented Mar 1, 2020

The lld arg has been resolved with v1.20...

I've created a separate issue for this: #102.

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