View Full Version : Howto pass commands to the linker script via .pro file
M4chin3
20th March 2015, 15:10
I'm using Qt 5.3.2 with GCC 4.8.2. I want to insert via the .pro file (using qmake) a section definition to the linker script created by qmake.
What I want to insert:
SECTIONS
{
.legacy_vars :
{
*myModule.o (.bss)
*myModule.o (.data)
}
.everything_else :
{
* (.bss)
* (.data)
* (.text)
}
}
Is this possible?
Thanks in advance!
To answer the question "why?":
I have legacy code in my project which I cannot change. But I need to reset its variables to reset its state. At the same time most of them are static and dont have functions to access them. Therefore I want to map the legacy codes variables to a defined section, read them when starting my program and if needed write them back in order to reset this part of the program.
wysota
21st March 2015, 11:26
What is a "linker script"? qmake only creates a Makefile.
ChrisW67
21st March 2015, 21:43
The Gnu ld linker is using a built-in "script" the vast majority of the time, including when invoked by a qmake generated Makefile. You can supply your own script using the linker -T option or by listing a script among the object files to be linked.
https://sourceware.org/binutils/docs/ld/Scripts.html#Scripts
You should look at the QMAKE_LFLAGS variable for this.
M4chin3
23rd March 2015, 19:49
The Gnu ld linker is using a built-in "script" the vast majority of the time, including when invoked by a qmake generated Makefile. You can supply your own script using the linker -T option or by listing a script among the object files to be linked.
https://sourceware.org/binutils/docs/ld/Scripts.html#Scripts
You should look at the QMAKE_LFLAGS variable for this.
Hi Chris,
thanks for your answer. I took a look at the link you posted and the qmake variable QMAKE_LFLAGS. This kind of does what I want but i ran into some problems:
After adding my script (with -T myscrift.ldf) the built-in script is no more loaded and it seems none of my .o files are linked together -> the program is not able to run anymore. I tried the simple example (https://sourceware.org/binutils/docs/ld/Simple-Example.html#Simple-Example) in this case, which does basically what I want to achieve. For me it seems the INPUT (.o files) are missing.
In this case my problems are:
1. Adding my .o files via INPUT requires a absolut or relativ path depending on the build path. But I dont know were my collegues will build their programs so everybody would need to adapt their linker scripts :-(
2. If done so (with a machine depending relativ or absolut path) it seems i need to link a crt0.o file or something (there is not much on the net about this it seems). Were do I find information about this? (Not even the GCC manual is very informativ in this case).
Thanks in advance!
M4chin3
30th March 2015, 12:28
Any further ideas? I'm still stuck on this :-(
M4chin3
31st March 2015, 12:52
Found a solution and posted it on Stackoverflow:
https://stackoverflow.com/questions/29167222/howto-pass-commands-to-the-linker-script-via-pro-file-qt/29366901#29366901
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.