7 ms·
How to compile C apps with musl and Clang
- vezzy-fnord 11y agoThe more awareness musl gets, the better. See also Sabotage Linux, a musl-based distro: https://github.com/sabotage-linux/sabotage https://github.com/sabotage-linux/sabotage
- andolanra 11y agoThere's also Void Linux, which has musl and glibc versions of packages and offers both musl-based and glibc-based download images: http://www.voidlinux.eu/ http://www.voidlinux.eu/
- raphaelss 11y agoThere's Alpine Linux too: http://www.alpinelinux.org/ http://www.alpinelinux.org/
- nickpsecurity 11y agoI'll check out these distro's in the near future. I at least got a laugh out of what I saw on alpine's homepage: "Simple. Small. Secure." right next to "ISO 298MB." I know I'm getting old when people think a 298MB system is simple, small, or secure. Lol...
- jzelinskie 11y agoThe Alpine Linux docker image is only a couple megabytes[0]. There are quite a few people (including myself) using it as a light-weight OS for their containers. [0]: https://github.com/gliderlabs/docker-alpine https://github.com/gliderlabs/docker-alpine
- nickpsecurity 11y agoNow that is more like it!
- sams99 11y agofor example, my redis container (samsaffron/redis) is 20mb, the official(tm) redis container is based on ubuntu is 100mb
- buserror 11y agoThere is also my own 'minifs' https://github.com/buserror/minifs https://github.com/buserror/minifs ; it's targeted at embedded, but it works fine on x86s too. Haven't ported it to musl yet (mostly due to the fact that musl wasn't yet merged into crosstool-NG) but that's high on my list. One thing minifs does is that it has a 'cross linker' took that jettisons every piece of code/library that is not actively linked by executable; also, instead of installing everyone's crap everywhere, I build the distro the other way around, and 'pick and chose' the bits that packages need until they work.
- fizixer 11y agomusl is great, but it would great if there was something at the compiler level that is better than both gcc and LLVM/Clang. LLVM/Clang is a step in the right direction but it's quite bloated because of support for C++, Objective-C etc (for C standards at least); not to mention it's written in C++. Being a Python/C hybrid enthusiast, I looked into taking something like Eli Bendersky's pycparser and making it featureful (preprocesser parsing at the minimum), but haven't done anything in that direction. Maybe some way of combining pycparser and tcc.
- koko775 11y agoWhat's wrong with being written in C++? It's a high-level, fast language with higher-level abstractions and better typesafety than C and decades of expertise built up around it. Sure, that means it has some legacy bits that need to be supported, but to some degree that's the price of having a mature codebase. Having compiled LLVM and rooted through its internals trying to implement a plugin, it looks pretty well-architected and internally consistent. Codebases that cover as much as LLVM+Clang do being that clean is a rare sight, IMO. And it's not slow.
- pmelendez 11y ago> What's wrong with being written in C++? Many C devs love to hate C++. I guess is something like some C++ devs love to hate Java. It's a bit of a heritage issue :) C++ does the job for me... it's is almost as powerful as it is complicated but I find that a fair trade off (YMMV)
- andresmanz 11y agoActually, I love C, C++ and Java all the same. They are great tools for writing great code. But regarding the comments I've stumbled upon, I think you're right.
- fizixer 11y agoNothing wrong with C++ per se, if you're a C++ programmer. First, I assume this is a musl thread, so I'm assuming C++ people might not be interested in it in the first place (I'd be surprised if C++ communities discuss the bloat of glibc let alone seeking its minimal C alternatives like musl instead of going for C++ solutions like boost and what not). Second, having hung around people who discuss the bloat of glibc, and strive for white-box and minimalism, of which musl is a result (this includes, but not limited to, communities like suckless, and cat-v.org), speaking of musl and clang in the same line would be odd at the least, considering clang is ~600k+ lines of C/C++, when there is a C-only tcc compiler at ~60k+, so it's likely clang is doing something (a lot of things) that C programmers have no interest in. Although I should admit these minimalist C communities might not have a good opinion of Python either (that's one of my personal interests).
- stefanmielke 11y agoDid someone acessed the website through mobile? I can't go past the title. Edit: Using an iPad 2.
- GFK_of_xmaspast 11y agoReal classy sample program there.
- mschuster91 11y agoExcuse the noob question, but why are there different libc implementations at all? I mean, their featureset is defined by standard, so all implementations should strive for the maximum performance - so where comes the bloat from? Support for multiple archs is of course a valid source for percieved bloat, but that should matter only at compile time?
- wtallis 11y agoI think you'd be surprised at how much variation there is in the feature set. libc isn't just the C standard library as defined by the language standard. It's the OS standard library too, and includes POSIX stuff and some de facto standard stuff and some OS-specific stuff. The musl author has a comparison table: http://www.etalabs.net/compare_libcs.html http://www.etalabs.net/compare_libcs.html Historically, the biggest reasons for alternate libcs have been to make tradeoffs for use on embedded systems (uClibc) or political/license differences.
- kryptiskt 11y ago> Historically, the biggest reasons for alternate libcs have been to make tradeoffs for use on embedded systems (uClibc) or political/license differences. And also the toxic maintainership of glibc in the Drepper era.
- deleted 11y ago[deleted]
- vezzy-fnord 11y agoHere's an article from the musl wiki that explains differences from glibc: http://wiki.musl-libc.org/wiki/Functional_differences_from_glibc http://wiki.musl-libc.org/wiki/Functional_differences_from_g... All the bugs discovered by musl, and how many are glibc-related: http://wiki.musl-libc.org/wiki/Bugs_found_by_musl http://wiki.musl-libc.org/wiki/Bugs_found_by_musl If you want to know why someone would want to replace glibc, then I give you a challenge: figure out how glibc implements printf(3). Good luck. The answer is: http://blog.hostilefork.com/where-printf-rubber-meets-road/ http://blog.hostilefork.com/where-printf-rubber-meets-road/
- esjeon 11y agoI've been digging musl + clang too. Here's my wrapper script that I use to compile a number of projects: https://github.com/esjeon/musl-clang https://github.com/esjeon/musl-clang This isn't perfect, but kinda works (even with autoconf). I also tried to add musl support into LLVM/clang, but I've been too busy recently, and won't be able to work on it for a while. A side note: Clang is such a beauty whose structure is so easy to understand yet very extendible. There are actually few things to be done on clang to support musl. Just implement a proper frontend, and you're mostly done. But it's kinda difficult to patch codes which assume glibc, and the fact that musl refuses to export __MUSL__ macro makes the job even harder.
- gct 11y agoMust everything be an "app"? Whatever happened to programs or god forbid unabbreviated applications
- IshKebab 11y agoPrograms were called apps long before the iphone.
- justincormack 11y agoYou will after a bit run into issues using Musl with a wrapper script, in my experience, and you are better off using a Musl based distro. You can run one in a chroot, I used to use Sabotage like that quite a bit, or if you use Docker you can just use "FROM alpine" and everything will be nice and statically linked, or you can do an install in a VM.
- sriku 11y agoSeems impossible to read the article on an iphone.