Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does sun C++ compiler change symbol names when compiling with debug infos?
    primarykey
    data
    text
    <p>I have this source file:</p> <pre><code>// ConstPointer.cpp const short * const const_short_p_const = 0; const short * const_short_p = 0; </code></pre> <p>and compiled it with and without debug infos (SUN C++ Compiler 5.10):</p> <pre><code># CC ConstPointer.cpp -c -o ConstPointer.o # CC -g ConstPointer.cpp -c -o ConstPointer-debug.o </code></pre> <p>Here are the symbol names of the object file <strong>without</strong> debug information:</p> <pre><code># nm -C ConstPointer.o ConstPointer.o: [Index] Value Size Type Bind Other Shndx Name [2] | 0| 0|SECT |LOCL |0 |10 | [3] | 0| 0|SECT |LOCL |0 |9 | [4] | 0| 0|OBJT |LOCL |0 |6 |Bbss.bss [1] | 0| 0|FILE |LOCL |0 |ABS |ConstPointer.cpp [5] | 0| 0|OBJT |LOCL |0 |3 |Ddata.data [6] | 0| 0|OBJT |LOCL |0 |5 |Dpicdata.picdata [7] | 0| 0|OBJT |LOCL |0 |4 |Drodata.rodata [9] | 4| 4|OBJT |GLOB |0 |3 |const_short_p [8] | 0| 4|OBJT |LOCL |0 |3 |const_short_p_const </code></pre> <p>Here are the symbol names of the object file <strong>with</strong> debug information:</p> <pre><code># nm -C ConstPointer-debug.o ConstPointer-debug.o: [Index] Value Size Type Bind Other Shndx Name [4] | 0| 0|SECT |LOCL |0 |9 | [2] | 0| 0|SECT |LOCL |0 |8 | [3] | 0| 0|SECT |LOCL |0 |10 | [10] | 0| 4|OBJT |GLOB |0 |3 |$XAHMCqApZlqO37H.const_short_p_const [5] | 0| 0|NOTY |LOCL |0 |6 |Bbss.bss [1] | 0| 0|FILE |LOCL |0 |ABS |ConstPointer.cpp [6] | 0| 0|NOTY |LOCL |0 |3 |Ddata.data [7] | 0| 0|NOTY |LOCL |0 |5 |Dpicdata.picdata [8] | 0| 0|NOTY |LOCL |0 |4 |Drodata.rodata [9] | 4| 4|OBJT |GLOB |0 |3 |const_short_p </code></pre> <p>Why has the variable <code>const_short_p_const</code> another symbol name? <code>g++</code> does not change it, when compiling with debug information. It looks like a compiler bug to me. What do you think? The second <code>const</code> (constant pointer) leads to this.</p> <p><strong>EDIT for Drew Hall's comment:</strong> For example you have two files:</p> <pre><code>// ConstPointer.cpp const short * const const_short_p_const = 0; void foo(); int main(int argc, const char *argv[]) { foo(); return 0; } </code></pre> <p>and</p> <pre><code>// ConstPointer2.cpp extern const short * const const_short_p_const; void foo() { short x = *const_short_p_const; } </code></pre> <p>Compiling is fine:</p> <pre><code># CC ConstPointer2.cpp -g -c -o ConstPointer2.o # CC ConstPointer.cpp -g -c -o ConstPointer.o </code></pre> <p>but linking does not work because the symbols differ! The symbol name in ConstPointer2.o is <code>const_short_p_const</code>, but the symbol name in ConstPointer.o is <code>$XAHMCqApZlqO37H.const_short_p_const</code>.</p> <pre><code># CC ConstPointer.o ConstPointer2.o -o ConstPointer Undefined first referenced symbol in file const_short_p_const ConstPointer2.o </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload