1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Linking objects with GNU LD

Discussion in 'Embedded' started by Karl-Heinz, Feb 27, 2006.

  1. Karl-Heinz

    Karl-Heinz Guest

    Hi everybody,

    I am using the GNU GCC toolchain configured for m68k (cross compiler).
    I want to link several objects into an executable file. Unfortunately
    there are several c-functions compiled into one object but I don't want
    to use all functions in my executable. Looking into the map file I can
    see the unused functions in my executable. Is there a way to avoid this
    functions being in the executable (apart from splitting the functions
    in the c file)?

    Thanks in advance
    Karl-Heinz, Feb 27, 2006
    1. Advertisements

  2. Karl-Heinz

    Hans Odeberg Guest

    The gcc options -ffunction-sections and -fdata-sections will generate
    separate sections for the functions and data items in a file. (Assuming
    the output format can support this.)

    The ld option --gc-sections will remove unreferenced sections.
    Hans Odeberg, Feb 27, 2006
    1. Advertisements

  3. Karl-Heinz

    Karl-Heinz Guest

    If I try to do as described, I get .text and .data sections with
    different extensions, e.g. ".text.foo".
    If I link without the ld option --gc-sections the executable seems to
    be fine.
    Unfortunately the ld option --gc-sections leads to an executable which
    has empty .text and .data sections. What's wrong?
    Karl-Heinz, Mar 7, 2006
  4. For all anybody out here can guess: your build of binutils, your
    linker script, or both.
    Hans-Bernhard Broeker, Mar 7, 2006
  5. Karl-Heinz

    David Brown Guest

    It sounds like ld has concluded that none of the sections are used, and
    they can thus all be eliminated. Perhaps you need to explicitly
    reference your Start symbol (the name can vary), so that it's section is
    not removed, nor any section referred to by that section, and so on.
    David Brown, Mar 7, 2006
  6. Yup. That's how it works.
    Your linker script.

    Look at the input section specifiers below:

    ..text :
    etext = .;
    } > rom

    ..data : AT (__data_init_start)
    __data_start = .;
    __data_end = .;
    } > ram

    ..bss :
    __bss_start = . ;
    __bss_end = . ;
    } > ram
    Grant Edwards, Mar 7, 2006
  7. Ah. Good point.

    He may have to do a KEEP() on a few key functions in order to
    prime the pump.
    Grant Edwards, Mar 7, 2006
  8. Karl-Heinz

    Karl-Heinz Guest

    That's it! I forgot to add "ENTRY(start)" into my linker script and
    there was no symbol "start" in my crt0.
    Thanks to all for your help!
    Karl-Heinz, Mar 8, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.