[llvm-dev] Help with setting up ARM embedded clang + lld

765 views
Skip to first unread message

Scott Shawcroft via llvm-dev

unread,
Apr 30, 2017, 6:18:42 PM4/30/17
to llvm...@lists.llvm.org
Hi all,
I've been doing a ton of embedded work (bare metal ARM Cortex M0+ and
M4, hopefully RISCV in the future) in the last year and would love to
start using and hacking on the llvm toolchain. I've tried setting up
clang + lld but can't get lld to work because clang tries to launch gcc.
I realize support is early but I'd love to have a dev setup so I can
help fix things.

Could some help me setup my Makefiles in this project:
https://github.com/tannewt/circuitpython/tree/clang to use dev builds of
clang and lld? Thanks!
~Scott
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Rui Ueyama via llvm-dev

unread,
Apr 30, 2017, 6:29:24 PM4/30/17
to Scott Shawcroft, llvm-dev
Did you read http://lld.llvm.org/#using-lld? In short, you want to pass -use-ld=lld to clang to use ld.lld instead of ld.

Joerg Sonnenberger via llvm-dev

unread,
Apr 30, 2017, 6:32:40 PM4/30/17
to Scott Shawcroft, llvm...@lists.llvm.org
On Sun, Apr 30, 2017 at 03:18:35PM -0700, Scott Shawcroft via llvm-dev wrote:
> Hi all,
> I've been doing a ton of embedded work (bare metal ARM Cortex M0+ and
> M4, hopefully RISCV in the future) in the last year and would love to
> start using and hacking on the llvm toolchain. I've tried setting up
> clang + lld but can't get lld to work because clang tries to launch gcc.
> I realize support is early but I'd love to have a dev setup so I can
> help fix things.

clang doesn't know how to call a linker for baremetal, so it tries to
fallback to gcc. Just call the linker directly.

Joerg

Scott Shawcroft via llvm-dev

unread,
Apr 30, 2017, 6:33:40 PM4/30/17
to Rui Ueyama, llvm-dev
I did look at that and it doesn't work. Here is the line from the Makefile: https://github.com/tannewt/circuitpython/blob/clang/atmel-samd/Makefile#L300

And here is it as output from make:
clang version 5.0.0 (trunk 301735)
Target: armv6m-none--eabi
Thread model: posix
InstalledDir: /Users/tannewt/repos/llvm/build/bin
"gcc" -flto -v -fuse-ld=lld -march=thumb...
clang-5.0: error: unable to execute command: Executable "gcc" doesn't exist!clang-5.0: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

Scott Shawcroft via llvm-dev

unread,
Apr 30, 2017, 6:47:43 PM4/30/17
to Joerg Sonnenberger, llvm...@lists.llvm.org
Ok, thanks! I got it going that way. I'd still love to hear from anyone
off list working on similar stuff.
~Scott

Rui Ueyama via llvm-dev

unread,
Apr 30, 2017, 9:05:52 PM4/30/17
to Scott Shawcroft, llvm-dev
I'm interested in supporting embedded programs as well as supporting RISC-V. Let me know if I can help you.

Renato Golin via llvm-dev

unread,
May 1, 2017, 10:11:15 AM5/1/17
to Scott Shawcroft, LLVM Dev
On 30 April 2017 at 23:47, Scott Shawcroft via llvm-dev

<llvm...@lists.llvm.org> wrote:
> Ok, thanks! I got it going that way. I'd still love to hear from anyone
> off list working on similar stuff.

Hi Scott,

Peter (CC'd) is implementing support for ARM32 on LLD. There are a few
missing pieces, but most support has been upstreamed already.

AFAIK, the most important missing features are range extension chunks
(important for large code base, like Clang) and better support for
linker script files (more important to embedded cases, like yours).

Apart from that, "it should just work". :)

Let us know if you find anything else. Adding a bug to bugzilla and
copying us (in this thread, including Rui, Joerg, me, Peter) would be
the best way to fix issues.

cheers,
--renato

Scott Shawcroft via llvm-dev

unread,
May 1, 2017, 1:35:13 PM5/1/17
to Renato Golin, LLVM Dev
Awesome! I got lld running but it GCed all my sections away. :-) I'll
keep experimenting with it.
~Scott

Rui Ueyama via llvm-dev

unread,
May 2, 2017, 7:00:15 PM5/2/17
to Scott Shawcroft, LLVM Dev
That's interesting. Usually your code wouldn't be gc'ed because your entire code is reachable from _start.

Does your program depend on the feature that, if no -e option is given, the linker sets the beginning of the .text section to the entry point address?

Renato Golin via llvm-dev

unread,
May 3, 2017, 6:52:37 AM5/3/17
to Rui Ueyama, LLVM Dev
On 2 May 2017 at 23:59, Rui Ueyama <ru...@google.com> wrote:
> That's interesting. Usually your code wouldn't be gc'ed because your entire
> code is reachable from _start.

Baremetal doesn't need a _start.


> Does your program depend on the feature that, if no -e option is given, the
> linker sets the beginning of the .text section to the entry point address?

I believe that would help, yes. But there may be linker scripts that
can change that, so you need to be careful.

Rui Ueyama via llvm-dev

unread,
May 3, 2017, 2:52:34 PM5/3/17
to Renato Golin, LLVM Dev
On Wed, May 3, 2017 at 3:52 AM, Renato Golin <renato...@linaro.org> wrote:
On 2 May 2017 at 23:59, Rui Ueyama <ru...@google.com> wrote:
> That's interesting. Usually your code wouldn't be gc'ed because your entire
> code is reachable from _start.

Baremetal doesn't need a _start.


> Does your program depend on the feature that, if no -e option is given, the
> linker sets the beginning of the .text section to the entry point address?

I believe that would help, yes. But there may be linker scripts that
can change that, so you need to be careful.

If you want to do GC, you still need to teach linkers GC root symbols in some way, no? Otherwise, linkers cannot determine if a section is live or not.

Scott Shawcroft via llvm-dev

unread,
May 4, 2017, 12:48:22 PM5/4/17
to Rui Ueyama, Renato Golin, LLVM Dev
Yeah totally. I had marked some sections as used previously but haven't had a chance to look further into it. I'll try to take some time this weekend to poke at it further.

The project I'm working on is here: https://github.com/tannewt/circuitpython/tree/clang/atmel-samd in case you can't wait.
Thanks,
Scott

Sean Silva via llvm-dev

unread,
May 4, 2017, 5:51:04 PM5/4/17
to Scott Shawcroft, LLVM Dev
Staring at the makefile, it seems like -flto is used, which might run into the same "GC" related issue I was describing here about linker script KEEP directives not being factored into the internalization logic with LTO: http://lists.llvm.org/pipermail/llvm-dev/2017-February/110582.html

I don't think we ever got a reproducer for that issue though. If removing -flto fixes the GC issue (or the __attribute__((used)) workaround I describe in the link works), could you add `--reproduce repro.tar` to your LLD invocation and upload repro.tar in a bug report?

-- Sean Silva
 
Thanks,
Scott
Reply all
Reply to author
Forward
0 new messages