Thread overview
importC with gc-sections not work on linux
Feb 26
Dakota
Feb 26
Dakota
February 26

When I use importC to build a c library, there is a lot unused symbol missing.

I try add -L--gc-sections to dmd to workaround this issue.

I also try -L-dead_strip on macOS, it work as expected.

I do some google, some one suggestion use with -ffunction-sections, -f fdata-sections, dmd seems not support it.

Any tips to work this around ?

February 27
On 27/02/2024 1:28 AM, Dakota wrote:
> When I use importC to build a c library, there is a lot unused symbol missing.
> 
> I try add `-L--gc-sections` to dmd to workaround this issue.

This removes symbols, not keeps them.

You want the linker flag: ``--no-gc-sections``

"Enable garbage collection of unused input sections. It is ignored on targets that do not support this option. The default behaviour (of not performing this garbage collection) can be restored by specifying ‘--no-gc-sections’ on the command line. Note that garbage collection for COFF and PE format targets is supported, but the implementation is currently considered to be experimental."

https://sourceware.org/binutils/docs/ld/Options.html
February 26

On Monday, 26 February 2024 at 12:33:02 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

On 27/02/2024 1:28 AM, Dakota wrote:

>

When I use importC to build a c library, there is a lot unused symbol missing.

I try add -L--gc-sections to dmd to workaround this issue.

This removes symbols, not keeps them.

You want the linker flag: --no-gc-sections

"Enable garbage collection of unused input sections. It is ignored on targets that do not support this option. The default behaviour (of not performing this garbage collection) can be restored by specifying ‘--no-gc-sections’ on the command line. Note that garbage collection for COFF and PE format targets is supported, but the implementation is currently considered to be experimental."

https://sourceware.org/binutils/docs/ld/Options.html

I need remove symbol, since the problem is some symbol from importC reference to undefined symbol(need to be implement in d, but they will never used).

after remove the unused symbol, I don't need to add the implement all of them.