Results 1 to 6 of 6

Thread: Howto pass commands to the linker script via .pro file

  1. #1
    Join Date
    Mar 2013
    Posts
    29
    Thanks
    4
    Thanked 4 Times in 2 Posts

    Default Howto pass commands to the linker script via .pro file

    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:

    Qt Code:
    1. SECTIONS
    2. {
    3. .legacy_vars :
    4. {
    5. *myModule.o (.bss)
    6. *myModule.o (.data)
    7. }
    8. .everything_else :
    9. {
    10. * (.bss)
    11. * (.data)
    12. * (.text)
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Howto pass commands to the linker script via .pro file

    What is a "linker script"? qmake only creates a Makefile.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Howto pass commands to the linker script via .pro file

    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...s.html#Scripts
    You should look at the QMAKE_LFLAGS variable for this.

  4. #4
    Join Date
    Mar 2013
    Posts
    29
    Thanks
    4
    Thanked 4 Times in 2 Posts

    Default Re: Howto pass commands to the linker script via .pro file

    Quote Originally Posted by ChrisW67 View Post
    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...s.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...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!

  5. #5
    Join Date
    Mar 2013
    Posts
    29
    Thanks
    4
    Thanked 4 Times in 2 Posts

    Default Re: Howto pass commands to the linker script via .pro file

    Any further ideas? I'm still stuck on this :-(

  6. #6
    Join Date
    Mar 2013
    Posts
    29
    Thanks
    4
    Thanked 4 Times in 2 Posts

    Default Re: Howto pass commands to the linker script via .pro file

    Found a solution and posted it on Stackoverflow:

    https://stackoverflow.com/questions/...66901#29366901

Similar Threads

  1. HowTo read playlist pls file
    By KeineAhnung in forum Newbie
    Replies: 4
    Last Post: 19th August 2014, 20:45
  2. How to ran a batch file script using cmd?
    By kiboi in forum General Programming
    Replies: 3
    Last Post: 6th February 2013, 09:11
  3. need to run a .js script file
    By vcernobai in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2010, 08:03
  4. How to get value from Script file?
    By superinman in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2010, 23:06
  5. Reading commands from file
    By QtFan19 in forum Newbie
    Replies: 2
    Last Post: 1st January 2010, 22:15

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.