Skip to content

Rust fails to recognize libraries compiled with --link-args=-Wl,--gc-sections #8647

Closed
@mstewartgallus

Description

@mstewartgallus

Rust fails to recognize libraries compiled with --link-args=-Wl,--gc-sections, and errors out saying that the requested library is not found when someone attempts to use such a library. The --gc-sections option is useful for shaving a few bytes of a library. Unfortunately, the -Z print-link-args option does not work so I can't really debug the problem further.

My thoughts on this bug. Does rustc use the -r option? Is this problem the result of Rust's meta-data being garbage collected? Would tools other than ld not recognize the meta-data, and also strip it?

GNU ld's documentation on this option:

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

       --gc-sections decides which input sections are used by examining
       symbols and relocations.  The section containing the entry symbol and
       all sections containing symbols undefined on the command-line will be
       kept, as will sections containing symbols referenced by dynamic
       objects.  Note that when building shared libraries, the linker must
       assume that any visible symbol is referenced.  Once this initial set of
       sections has been determined, the linker recursively marks as used any
       section referenced by their relocations.  See --entry and --undefined.

       This option can be set when doing a partial link (enabled with option
       -r).  In this case the root of symbols kept must be explicitly
       specified either by an --entry or --undefined option or by a "ENTRY"
       command in the linker script.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions