Why does the Sun C ++ compiler change character names when compiling with debugging information?

I have this source file:

// ConstPointer.cpp const short * const const_short_p_const = 0; const short * const_short_p = 0; 

and compiled it with and without debugging information (SUN C ++ Compiler 5.10):

 # CC ConstPointer.cpp -c -o ConstPointer.o # CC -g ConstPointer.cpp -c -o ConstPointer-debug.o 

The following are the symbol names of the object file without debugging information:

 # 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 

Here are the symbol names of the object file with :

 # 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 

Why const_short_p_const variable have a different symbol name? g++ does not change it when compiling with debugging information. This seems like a compiler error. What do you think? The second const (constant pointer) leads to this.

EDIT for Drew Hall's comment: For example, you have two files:

 // ConstPointer.cpp const short * const const_short_p_const = 0; void foo(); int main(int argc, const char *argv[]) { foo(); return 0; } 

and

 // ConstPointer2.cpp extern const short * const const_short_p_const; void foo() { short x = *const_short_p_const; } 

Compilation in order:

 # CC ConstPointer2.cpp -g -c -o ConstPointer2.o # CC ConstPointer.cpp -g -c -o ConstPointer.o 

but the link does not work because the characters are different! The symbol name in ConstPointer2.o is const_short_p_const , but the symbol name in ConstPointer.o is $XAHMCqApZlqO37H.const_short_p_const .

 # CC ConstPointer.o ConstPointer2.o -o ConstPointer Undefined first referenced symbol in file const_short_p_const ConstPointer2.o 
+4
source share
1 answer

Maybe this is due to the fact that the global variable const implicitly static in C ++?

+2
source

All Articles