Dead Code Elimination

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Oct 22 08:04:09 UTC 2026


On 22/10/2026 8:50 PM, libxmoc wrote:
> On Wednesday, 21 October 2026 at 19:34:17 UTC, Walter Bright wrote:
>> On 10/21/2026 12:10 AM, libxmoc wrote:
>>> I disassembled both app and app.o, and `removeme` exists in both
>>
>> It's the job of the linker to remove uncalled functions.
>>
>> The compiler does not know what other code the result may be linked 
>> with, and what functions that other code calls.
> 
> So why didn't the linker remove the `removeme` function from the 
> executable?

For MSVC link `/OPT:REF` is only enabled with -release (uck).

https://github.com/dlang/dmd/blob/21cf5b1ae5510eb7566812b065db582024e89cd0/compiler/src/dmd/link.d#L283

https://learn.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=msvc-170

Other linkers may not be doing it by default as well.


More information about the Digitalmars-d mailing list