为什么会改变结构尺寸,更改可执行文件的大小? [英] Why would changing a structure size, change the size of an executable?

查看:158
本文介绍了为什么会改变结构尺寸,更改可执行文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很奇怪的问题,我正在调试,目前处于亏损状态,所以我想看看是否人有任何想法/主意。

Very strange issue I'm working to debug, currently at a loss so I wanted to see if anyone had any thoughts/ideas.

有是在我的code基炭车手之一(这是一个发行版uCLinux中的许多因素之一)一个定义:

There's a define in one of the char drivers in my code base (this is one of many drivers within a uCLinux distribution):

#define MAX_BUFSIZE 500

当我建立这样的我看到的输出包装尺寸:

When I build like this I see the output package size:

-rw-rw-r-- 1 mike users 1720620 Jan 16 11:00 gcl-kernel.pkg

当我改变定义为1000和重建:

When I change the define to 1000 and rebuild:

#define MAX_BUFSIZE 1000

-rw-rw-r-- 1 mike users 2359596 Jan 16 11:17 gcl-kernel.pkg

整体内核映像大大增加。那一个的#define 是在只有的变化。据我所知,运行时,这应该已经改变了可执行文件的RAM大小,它不应该做任何可执行文件的大小。

The overall kernel image greatly increases. That one #define was the only change. AFAIK, this should have changed the RAM size of the executable when running, it should not have done anything to the executable's size.

所以我的问题:

任何人都可以想到的任何原因,一个被修改的结构将改变最终图像的大小?

其他分析/信息,如果你关心:

Other analysis/information if you care:

我跟踪的这种用法在头文件中定义的一个结构:

I tracked usage of this to one structure defined in a header file:

typedef struct {
    int head;
    int tail;
    int status;
    int active;
    void * dev[MAX_BUFSIZE];
    char free[MAX_BUFSIZE];
    canmsg_t data[MAX_BUFSIZE];
    int count;
} msg_fifo_t;

每当我改变任何这些阵列,可执行文件的大小变化的大小。随时这种类型的新对象显示出来或在code中的可执行文件的大小的变化被除去,例如:

Anytime I change the size of any of those arrays, the executable size changes. Anytime a new object of this type shows up or is removed in the code the executable size changes, ex:

extern msg_fifo_t Tx_Bufx[];
extern msg_fifo_t Rx_Buf[];

有不同的输出可执行文件的大小则:

has a different output executable size then:

extern msg_fifo_t Tx_Bufx[];
//extern msg_fifo_t Rx_Buf[];

我试过,但我似乎无法创造这个问题我的x86系统调试问题上的缩小版,它必须有事可做与环境。 (对于uCLinux的2.4内核的ColdFire工具链建设)。

I've tried but I can't seem to create a smaller version of this issue on my x86 system to debug the problem, it must have something to do with the environment. (coldfire tool chain building for a uCLinux 2.4 kernel).

推荐答案

如果一个结构的实例已被宣布为静态,它会被分配无论是在 .BSS 段或的。DATA 段,这取决于它是否被0初始化。如果是这种情况,因为你加倍阵列的大小,这将增加最终二进制大小

If an "instance" of the structure has been declared as static, it will be allocated either in the .BSS segment or the .DATA segment of the binary, depending on whether it was 0 initialized or not. If this is the case, since you're doubling the size of the array, this will increase the final binary size.

这篇关于为什么会改变结构尺寸,更改可执行文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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