如何引用的启动的一个用户定义段在Visual Studio中,项目? [英] How to refer to the start-of a user-defined segment in a Visual Studio-project?

查看:107
本文介绍了如何引用的启动的一个用户定义段在Visual Studio中,项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我竭力要转换GNU工具链的使用ld链接的C程序,
使它编译为视觉工作室(2005年)项目。
该方案提出。资料-符号在不同的段,期间
段之间的初始化阶段它复制数据。指针到
启动和段的端部是在LD链接脚本定义。

我知道如何变量定位到不同的用户定义
段,但我还没有能够弄清楚如何定义连接常量
如_start_of_my_segment或者如果有类​​似的连接体的东西
脚本在Visual Studio。

我的目标是能够与,prefferably编译程序
没有修改的源 - code,它是指在定义链接器
符号,但在Visual Studio中的数据我自己的自定义布局
项目。

下面是一些例子C- code,说明我想要什么
做和(简装,可能是语法不正确的)版本
化妆脚本使用gcc / ld进行链接时使用。

任何提示将不胜AP preciated!

 的#pragma data_seg(MY_DATA_FOO)
的#pragma data_seg(MY_DATA_BAR)
的#pragma评论(连接/部分:MY_DATA_BAR,R)__declspec(分配(MY_DATA_FOO))INT foo1;
__declspec(分配(MY_DATA_FOO))INT foo2的;__declspec(分配(MY_DATA_BAR))INT BAR1 = 1;
__declspec(分配(MY_DATA_BAR))INT BAR2 = 2;的#pragma data_seg()
无效测试(){
    foo1 = BAR1;
    foo2的= BAR2;    //我宁愿做这个作为
    //的extern unsigned int类型__start_of_MY_DATA_FOO;
    //的extern unsigned int类型__start_of_MY_DATA_BAR;
    //的extern unsigned int类型__size_of_MY_DATA_BAR;
    //的memcpy(__ start_of_MY_DATA_FOO,_start_of_MY_DATA_BAR,_size_of_MY_DATA_BAR);
}

伪链接脚本(这将是对Visual Studio中的等价

  MEMORY
{
  富:有机= 0x1000中,LEN = 0x100处
  条:组织=为0x2000,LEN = 0x100处
}截面
{
    组:
    {
        MY_DATA_FOO:{}
        __start_of_MY_DATA_FOO = ADDR(MY_DATA_FOO);
        __end_of_MY_DATA_FOO =。
        __size_of_MY_DATA_FOO = SIZEOF(MY_DATA_FOO);
    }>富    组:
    {
        MY_DATA_BAR:{}
        __start_of_MY_DATA_BAR = ADDR(MY_DATA_BAR);
        __end_of_MY_DATA_BAR =。
        __size_of_MY_DATA_BAR = SIZEOF(MY_DATA_BAR);
    }>酒吧
}


解决方案

填充可以通过合并细分除去

例如:

 的#pragma data_seg(。foo_begin)
的#pragma data_seg(。foo_data)
的#pragma data_seg(。foo_end)的#pragma评论(连接器,/merge:.foo_begin=.foo)
的#pragma评论(连接器,/merge:.foo_data=.foo)
的#pragma评论(连接器,/merge:.foo_end=.foo)__declspec(分配()foo_begin)INT foo_begin_marker;
__declspec(分配()foo_end)INT foo_end_marker;__declspec(分配()foo_data)INT foo_data;

I'm struggling to convert a C-program linked with ld, of the gnu tool-chain to make it compile as a visual-studio (2005) project. The program puts .data-symbols in different segments and during an initialization phase it copies data between segments. Pointers to the start and end of the segments are defined in the ld linker script.

I understand how to locate the variables into different, user-defined segments, but i havent been able to figure out how to define linker constants such as _start_of_my_segment or if there is something similar to a linker script in Visual Studio.

My goal is to be able to compile the program with, prefferably no modifications to the source-code that refers to the linker-defined symbols, but with my own custom layout of the data in the Visual Studio project.

Below is some example C-code that illustrates what i'd like to do and a (stripped-down, possibly syntax-incorrect) version of the make-script used when linking with gcc/ld.

Any hints would be greatly appreciated!

#pragma data_seg( "MY_DATA_FOO" )
#pragma data_seg( "MY_DATA_BAR" )
#pragma comment(linker, "/section:MY_DATA_BAR,R")

__declspec(allocate("MY_DATA_FOO")) int foo1;
__declspec(allocate("MY_DATA_FOO")) int foo2;

__declspec(allocate("MY_DATA_BAR")) int bar1 = 1;
__declspec(allocate("MY_DATA_BAR")) int bar2 = 2;

#pragma data_seg( )
void test() {
    foo1 = bar1;
    foo2 = bar2;

    // i would rather do this as 
    //extern unsigned int __start_of_MY_DATA_FOO;
    //extern unsigned int __start_of_MY_DATA_BAR;
    //extern unsigned int __size_of_MY_DATA_BAR;
    //memcpy(__start_of_MY_DATA_FOO, _start_of_MY_DATA_BAR, _size_of_MY_DATA_BAR);
}

Pseudo link-script (what would be the equivalent for Visual Studio

MEMORY
{
  foo:  org=0x1000, len=0x100
  bar:  org=0x2000, len=0x100
}

SECTIONS
{
    GROUP:
    {
        MY_DATA_FOO : {}
        __start_of_MY_DATA_FOO = ADDR(MY_DATA_FOO);
        __end_of_MY_DATA_FOO = .;
        __size_of_MY_DATA_FOO = SIZEOF(MY_DATA_FOO);
    } > foo

    GROUP:
    {
        MY_DATA_BAR : {}
        __start_of_MY_DATA_BAR = ADDR(MY_DATA_BAR);
        __end_of_MY_DATA_BAR = .;
        __size_of_MY_DATA_BAR = SIZEOF(MY_DATA_BAR);
    } > bar
}

解决方案

padding can be removed by segments merging

for example

#pragma data_seg(".foo_begin")
#pragma data_seg(".foo_data")
#pragma data_seg(".foo_end")

#pragma comment( linker, "/merge:.foo_begin=.foo" )
#pragma comment( linker, "/merge:.foo_data=.foo" )
#pragma comment( linker, "/merge:.foo_end=.foo" )

__declspec(allocate(".foo_begin")) int foo_begin_marker;
__declspec(allocate(".foo_end")) int foo_end_marker;

__declspec(allocate(".foo_data")) int foo_data;

这篇关于如何引用的启动的一个用户定义段在Visual Studio中,项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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