This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Strange error (suspect comiler or linker fault)

This one is driving me crazy, so I just wanted to know if anyone has any hints as to how I might fix this.

I have compiled zlib as a library, and I have included the lib-file in my project along with the header files for the exported functions. This works, and there are no complaints from the compiler or linker.

However, a very strange thing happened when I was modifying some code I was working on. It was a very simple change, I added a missing space to a literal string somewhere in my code. This caused a completely different part of my code (in a different source file) which used zlib to decompress data, to actually stop working (the zlib inflate()-function returned an error, even though it was given the same source data).

The object file with the code that started failing was unchanged, but there was a positional change in the final image due to the one extra space character in the literal string.

How can this happen? The library was unchanged, the code using it was unchanged, yet it failed.

If I change the optimization level I can "fix" the error, but that is of course just conicidence.

I'm using RealView MDK-ARM Version: 3.23.

I think I may have tried almost all combinations of optimizations and other options, both when compiling the library and the actual project. Sometimes it works, sometimes it doesn't.

Can anyone please shed some light for me? I am probably going bald any day soon... :-)

Parents
  • "If I change the optimization level I can "fix" the error, but that is of course just conicidence."

    No, it is probably not just coincidence.

    it probably goes to show that there is a fault in your code, but you just happen to get away with it at the other optimisation level.

    eg, have you checked that everything that ought to be volatile is volatile...?

    "I added a missing space to a literal string somewhere in my code."

    That could mean that everything after that location in your code space is moved up by 1 byte - so, for instance, something that was correctly aligned before is now mis-aligned...
    Or something got pushed into a faulty address range on your target...

Reply
  • "If I change the optimization level I can "fix" the error, but that is of course just conicidence."

    No, it is probably not just coincidence.

    it probably goes to show that there is a fault in your code, but you just happen to get away with it at the other optimisation level.

    eg, have you checked that everything that ought to be volatile is volatile...?

    "I added a missing space to a literal string somewhere in my code."

    That could mean that everything after that location in your code space is moved up by 1 byte - so, for instance, something that was correctly aligned before is now mis-aligned...
    Or something got pushed into a faulty address range on your target...

Children