Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove warning: link.res contains output sections; did you forget -T?

Tags:

linux

ld

pascal

fpc

I'm using fpc compiler and I want to remove this warning. I've read fpc's options but I can't find how to do that. Is this possible? it appear when I run command:

fpc foo.pas

out:

Target OS: Linux for i386 Compiling foo.pas Linking p2 /usr/bin/ld: warning: link.res contains output sections; did you forget -T? 79 lines compiled, 0.1 sec

like image 761
Jack Avatar asked Nov 25 '13 05:11

Jack


2 Answers

It's a bug in certain LD versions. Just ignore it for now, or see if your distro has an update for your LD. (package binutils)

http://www.freepascal.org/faq.var#unix-ld219

like image 152
Marco van de Voort Avatar answered Nov 09 '22 12:11

Marco van de Voort


It‘s not a bug because ld behaves like its specification. The man page of ld 2.28 reads:

If the linker cannot recognize the format of an object file, it will assume that it is a linker script. A script specified in this way augments the main linker script used for the link (either the default linker script or the one specified by using -T). This feature permits the linker to link against a file which appears to be an object or an archive, but actually merely defines some symbol values, or uses "INPUT" or "GROUP" to load other objects. Specifying a script in this way merely augments the main linker script, with the extra commands placed after the main script; use the -T option to replace the default linker script entirely, but note the effect of the "INSERT" command.

TL;DR ☺. In a nutshell: In most cases the users are not aware of the linker script they are using because a “main script” (= default script) is provided by the tool chain. The main script heavily refers to intrinsics of the compiler-generated sections and you have to learn the ropes to change it. Most users do not.

The common approach to provide your own script is via the -T option. That way the main linker script is ignored and your script takes over control over the linkage. But you have to write everything from scratch.

If you just want to add a minor feature, you can write your specs into a file and append the file name to the command line of ld (or gcc / g++) without the -T option. That way the main linker script still does the chief work but your file augments it. If you use this approach, you get the message of the header of this thread to inform you that you might have provided a broken object unintentionally.

The source of this confusion is that there is no way to specify the rôle of the additional file. This could easily be resolved by adding another option to ld just like the -dT option for “default scriptfile”: Introduce a -sT option for “supplemental scriptfile”.

like image 27
hermannk Avatar answered Nov 09 '22 13:11

hermannk