Why would changing a structure size, change the si

2019-07-23 18:38发布

问题:

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

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

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

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.

So my question:

can anyone think of any reason that a structure being modified would change the final image 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;

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[];

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).

回答1:

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.