GCC:如何让GCC在.text部分的开头放置'main'函数? [英] GCC: how to tell GCC to put the 'main' function at the start of the .text section?

查看:542
本文介绍了GCC:如何让GCC在.text部分的开头放置'main'函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习一些ARM编程,并且陷入了一个令人讨厌的问题。我用来编译源码的工具链是Sourcery CodeBench Lite 2013.05-23(可以在这里找到: https: //sourcery.mentor.com/GNUToolchain/release2449

我需要告诉GCC或LD或OBJCOPY将编译后的字节码'。main'函数在.text部分开始。



有什么办法可以达到这个目的吗? (可能是通过链接脚本?)



谢谢

解决方案

解决了这个问题。无论谁面对它:


  • 使用GCC编译时,在命令行中添加 -ffunction-sections 选项,线。这个会告诉GCC将每个功能放在一个单独的部分中。部分名称的格式为 .text。#function name#,不带(也就是说,如果函数属于.text部分[默认情况下其次,使用链接器脚本将这些功能部分排序到最终的big .text部分。 举例来说,将 main 函数放在.text部分的开头将导致LD脚本看起来像这样:

     ENTRY(main)
    SECTIONS
    {
    .text:
    {
    *(。text.main);
    *(。text *);
    }
    }



I've just started learning some ARM programming and I've got stuck in a slightly annoying problem. The toolchain I'm using to compile my sources is Sourcery CodeBench Lite 2013.05-23 (can be found here: https://sourcery.mentor.com/GNUToolchain/release2449)

What I would need is to tell GCC or LD or OBJCOPY to put the compiled bytecode of the 'main' function at the beginning of the .text section.

Is there any way to achieve this? (maybe through a linker script?)

Thank you

解决方案

Solved the problem. For whoever faces it:

  • When compiling with GCC, add the -ffunction-sections option in the command-line. This will tell GCC to put each function in a separate section. The format of the section name will be .text.#function name#, without the # (that is, if the function belongs to the .text section [ which by default is true ]).
  • Secondly, use a linker script to order these "function-sections" into the final big .text section. As an example, putting the main function at the beginning of the .text section would result in an LD script that looks approximately like this:

    ENTRY(main)
    SECTIONS
    {
        .text :
        {
            *(.text.main);
            *(.text*);
        }
    }
    

这篇关于GCC:如何让GCC在.text部分的开头放置'main'函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆