In around 2001 the ELF spec was changed to imply that common symbols should have type STT_COMMON. Gas does not support this. Moreover, the .type directive does not have "common" as a valid type.
.comm foo, 32 # .type foo, %common uncomment the line to get an error. nm -fsysv shows foo |00000020| C | OBJECT|00000020| |*COM*
Created attachment 2031 [details] Accept STT_COMMON as a symbol type and use it for ELF common symbols
Hi Richard, I have uploaded a patch which takes a stab at implementing support for the ELF STT_COMMON type. Would you care to have a look at it ? The issues that I think need to be considered are: * What should happen if a symbol is defined by some method other than the .comm pseudo op and then its type is set to common ? eg: .data foo: .word 4 .type foo,STT_COMMON At the moment the patch just arbitrarily moves the symbol into the common section, but is this correct. Maybe an error message should be issued instead ? * The patched assembler will now emit common symbols with the STT_COMMON type rather than the STT_OBJECT type. Are there build systems out there that depend on th eold behaviour ? * It is possible to have symbols with the STT_COMMON type but which are not in the common section. How should the binutils handle them ? For now the patch just treats them like STT_OBJECT symbols, which I think is the correct thing to do. Cheers Nick
The current assembler just ignores .type common,%common by default: [hjl@gnu-6 gas]$ cat x.s .common foo, 1 .type foo,%common [hjl@gnu-6 gas]$ ./as-new -o x.o x.s [hjl@gnu-6 gas]$ ../binutils/readelf -s x.o Symbol table '.symtab' contains 5 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 2: 0000000000000000 0 SECTION LOCAL DEFAULT 2 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3 4: 0000000000000001 1 OBJECT GLOBAL DEFAULT COM foo [hjl@gnu-6 gas]$ I am expecting COMMOM type for foo. I think we should add BSF_COMMON to support STT_COMMON.
Hi H.J. The STT_COMMON type will be generated if you configure the toolchain with --enable-elf-stt-common. This is not enabled by default because the loaders currently installed on most systems do not support symbols with the STT_COMMON type. Cheers Nick
Fixed already, I think.