Comments (9)
Woops, I didn't mean to close this. Sorry.
I just did a manual compilation and linking of this example with ldc 2.9. The doNothing() code is removed properly so it appears to be a problem with ldc2 only (or at least a newer ldc than the llvm-2.9 based version). Just thought I would let people know that this example used to work, so that the search could be narrowed down to new ldc2/llvm-3.0 changes.
Thanks,
K.Wilson
from ldc.
Ok, then to clarify my configuration, I'm using revision 4e8afa8 of LDC2 (the latest trunk revision at the time of writing) with LLVM3. This issue shows up on both a Debian testing and Ubuntu 10.04 box.
from ldc.
I've reverse-engineered what's going on here, and it's not a bug per se, just different configurations. When DMD is run with the -lib switch, it creates an archive where basically every function gets its own object file. Therefore, object files that contain dead code are never pulled in. By default there is never any dead code elimination within an object file. It only happens at the level of the whole object file.
GDC used to write one object file per source file, which is more coarse-grained but still prevents most manifestations.
LDC puts one gigantic object file in the archive it creates. By default this contains one huge linker section. Therefore, when any of this stuff gets pulled in, all of it does.
To get DMD-like behavior, all you have to do is compile your libraries with -ffunction-sections and link with -L--gc-sections. The former causes every function to be put in its own section in the object file. The latter causes the linker to garbage collect unused sections, and hence not complain when an undefined symbol is referenced from dead code.
from ldc.
Shouldn't this be the default then?
from ldc.
Yes, this probably warrants closer discussion.
from ldc.
...In that case maybe we should build Phobos and Druntime with -ffunction-sections and -fdata-sections (which does the same thing as -ffunction-sections, except for static data instead of functions), too. It might result in smaller binaries.
from ldc.
Yep, with gdc I use phobos compiled with -ffunction-sections -fdata-sections just fine.
from ldc.
Other opinions?
from ldc.
We are building with --gc-sections by default now.
from ldc.
Related Issues (20)
- Performance regression when updating from 1.34 to 1.35 HOT 4
- ldc 1.35.0 fails to build with llvm 17 HOT 3
- cmake fails on macos HOT 1
- Miscompilation with -opaque-pointers=true with LLVM16 HOT 3
- FrontEnd PGO (FE PGO) vs IR PGO HOT 2
- Crash when compiling function missing return with inline assembly
- Implement CFI support
- WebAssembly Exceptions HOT 8
- LDC druntime calls private dyld API, which is not allowed by Apple. HOT 6
- perf: optimize indexing in inner loops HOT 2
- double-nested try/finally causes ICE on Windows (but not on Linux) HOT 5
- `"a" is "b"` is true HOT 2
- Time trace: large sections of std.stdio isn't showing up as what it is doing
- Re: Error: Instruction does not dominate all uses! HOT 4
- Print import paths HOT 3
- ldc ignore mtriple when use with --fsanitize=address HOT 1
- libLTO-ldc.dylib missing in 1.36 Release for osx-arm64 HOT 2
- DWARF for static members are wrong HOT 2
- ICE on `&(foo[])[0]`
- 'Instruction does not dominate all uses' wrt. ternary expressions using array literals HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ldc.