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

Use clang-8 to build linux libgc and libcrystal #57

Merged
merged 1 commit into from
Feb 9, 2020

Conversation

bcardiff
Copy link
Member

@bcardiff bcardiff commented Feb 7, 2020

@RX14 do you have any reason to not include this change proposed in the referenced issue?

Fixes crystal-lang/crystal#8653

It fix the

libgc.a(alloc.o): unrecognized relocation (0x2a) in section `.text'

issue for me locally

@bcardiff bcardiff requested a review from RX14 February 7, 2020 20:00
@j8r
Copy link
Contributor

j8r commented Feb 7, 2020

It could be better to use the LLVM toolchain everywhere:

  • clang compiler
  • lld linker

Side note: it will result on smaller Alpine containers, the linker being separated from the compiler in the packages.

@bcardiff
Copy link
Member Author

bcardiff commented Feb 8, 2020

@j8r that is outside of my current goal that is to bring trusty back to the party. My alpine-fu is zero, so I am not sure how to accomplish what you propose. I guess it sounds good.

@j8r
Copy link
Contributor

j8r commented Feb 8, 2020

@bcardiff what I'm essentially saying is in this Dockerfile, both clang and gcc would be used - I suppose it's something better to avoid.
Then if clang is used in this file instead of gcc, why not using lld then.

After that, if all works (in theory), there will be size advantage for the built images (maybe for Ubuntu, but especially Alpine)

@straight-shoota
Copy link
Member

@j8r Unfortunately, it's not that easy. The crystal compiler doesn't interface with the linker (ld or lld) directly, but invokes the C compiler (CC) which then takes care about configuring the linker. This command is printed when --cross-compile is given. We can use clang as a drop-in replacement for that. Although that adds another dependency again, clang is smaller than gcc, so it would be an net win.
Both gcc and clang can be told to use lld as linker. But... when you try that with clang (and no gcc installed), the linker fails because its unable to find libgcc. It seems every Crystal binary is actually linked against libgcc. That's not obvious from the linker arguments generated by the compiler, but added implicitly by cc and clang. I suppose
this SO question targets that: https://stackoverflow.com/questions/51173869/why-does-clang-still-need-libgcc-a-to-compile-my-code
Maybe it's possible to improve that. But it's probably gonna take some effort. Maybe it could be as easy as providing libgcc as a standalone library. But even that might not be a quick job. While it's generally good to reduce dependencies, the main result would just be that the alpine docker image is a couple of megabytes smaller. To me that's not worth the investment, at least not in the near future.

Copy link
Contributor

@RX14 RX14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, why not!

@RX14 RX14 merged commit 70a3f17 into master Feb 9, 2020
@straight-shoota straight-shoota deleted the build-libs-with-clang-8 branch February 9, 2020 15:54
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

Successfully merging this pull request may close these issues.

unrecognized relocation (0x2a) in section `.text'
4 participants