Pregunta

I've got a highly optimized compiled C++ object file (compiled with g++, specifying -O3 -g -march=amdfam10 -Wall) with debug info.

I'm using objdump -S "objname".

Unfortunately interleaving the source doesn't seem to work, because sometimes I see the same group of lines (not just a single line) repeated, and not just one code line but multiple of them, many times, followed by only one assembly line, then other 3/4 source lines, without making much sense.

I see for example, 3/4 C++ code lines with iterators, and maps initializations followed by only 1/2 ASM lines? Does it make sense?

Any idea what might be happening?

¿Fue útil?

Solución

Optimized code (especially with the aggressive optimizations turned on by O3) no longer has a direct correspondence with the source. For instance, the compiler will often eliminate variables since the value doesn't ever need to be stored in memory, only in registers. It will also reorder operations so that they are faster. For instance, a simple optimization is to turn a conditional inside a loop into a conditional that chooses between two different loops, turning something like this

while(1){
    if(foo){
        bar();
    } else {
        baz();
    }
}

into something like this

if(foo){
    while(1){
        bar();
    }
} else {
    while(1){
        baz();
    }
}

which is equivalent, but avoids making the comparison on each iteration.

If you want to be able to see a direct correspondence with the source code, O1 is about as high as you can go.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top