Giter Club home page Giter Club logo

Comments (9)

wilsonk avatar wilsonk commented on May 28, 2024

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.

dsimcha avatar dsimcha commented on May 28, 2024

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.

dsimcha avatar dsimcha commented on May 28, 2024

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.

Trass3r avatar Trass3r commented on May 28, 2024

Shouldn't this be the default then?

from ldc.

dnadlinger avatar dnadlinger commented on May 28, 2024

Yes, this probably warrants closer discussion.

from ldc.

dsimcha avatar dsimcha commented on May 28, 2024

...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.

Trass3r avatar Trass3r commented on May 28, 2024

Yep, with gdc I use phobos compiled with -ffunction-sections -fdata-sections just fine.

from ldc.

Trass3r avatar Trass3r commented on May 28, 2024

Other opinions?

from ldc.

dnadlinger avatar dnadlinger commented on May 28, 2024

We are building with --gc-sections by default now.

from ldc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.