Hi,
Is there a way to control the layout of the initialized data segment of a MACH-O binary?
The problem I'm having is that some code I am porting expects a static char array, followed by a char array to be in the order defined in the source code, but this isn't the case when compiled with Xcode. I know it sounds horrible (it is!), but the binary is scanned by an external app for copy protection purposes and these two buffers must be laid out correctly in order for it to work. I can't change it... and needless to say, the CodeWarrior (OS 9) and Windows versions don't have this problem.
So, to demonstrate, in the code I have (example, not real!):
static unsigned char gBuffer1[8] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
unsigned char gBuffer2[8] = { 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'};
and the external app expects to see "abcdefghhgfedcba" in the data area of the binary.
Unfortunately, the resultant layout from an Xcode compile gives a binary with this:
"hgfedcba<lots of strings and other data here>abcdefgh"
For what it's worth, this is a Carbon app.
Any suggestions highly welcome!
As a temporary workaround, I believe passing -fno-common to gcc will put them together although I don't know how reliable that would be. Some other compilers I've encountered don't have common sections by default so it might be an option you want anyway if the code was written with that in mind.
Obviously, this isn't the proper fix as others have suggested.