views:

69

answers:

2

I'm testing to make sure that my cross compiler is working. When I compile hello world it seems to compile fine but when I change hello.cpp to the same program that loops 1000 times the elf file generated is exactly the same size. No matter what changes I make the file is always the same size and as far as I can tell, has the same contents. What would cause this?

+6  A: 

What does it mean "as far as I can tell"? You can check that with diff or some other utility. If you're using a cross-compiler to some small device, it might have a reason to allocate the output in blocks of a specified size, or even preallocate the target's device size. Can you verify with some tool that you indeed get exactly the same file?

viraptor
It looks like I don't actually get exactly the same file. What concerns me now is that I supposedly asserted the static libraries flag in gcc so no dynamic linking should occur. When I compile hello world and an empty main they are "nearly" identical even though displaying hello world often requires many many instructions.
Dan Snyder
+2  A: 

Without more details, it would be hard to help you much. But here are some ideas:

  1. As Bobby says, are you sure that you're passing the right files to it?

  2. Are you sure that the executable that you're running is the one being generated?

  3. Is the compilation actually succeeding? The executable you're running could be the one from the last successful run of the compiler rather than your current attempts to compile.

  4. As viraptor suggested, are you absolutely sure that the files are the same? Does diff say that they're the same? It's possible that whatever changes you're making are getting optimized out - especially if you're making changes in code that isn't even called.

Really, the odds are that you're not really doing what you think your doing.

  1. Make sure that your compilation commands - be they on the command-line or in a make file or whatever - are correct.

  2. You should probably delete your executable to make sure that a new one is actually being generated.

  3. See what the compiler does if you specifically try and compile junk. It shouldn't compile. If it is, then you're not compiling what you think you're compiling.

Jonathan M Davis
I ran diff and apparently "as far as I can tell" isn't quite far enough. I think that the .text section involved with the actual program for each program I've compiled is just negligible compared to the other segments of the elf file. I compiled hello.cpp, nothello.cpp and junk.cpp. hello and nothello were different (albeit not THAT different) and junk did not compile.
Dan Snyder