Bug 4799 - Common symbols not given type STT_COMMON
Summary: Common symbols not given type STT_COMMON
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-17 12:20 UTC by Richard Earnshaw
Modified: 2020-01-31 06:54 UTC (History)
2 users (show)

See Also:
Host:
Target: *elf
Build:
Last reconfirmed:


Attachments
Accept STT_COMMON as a symbol type and use it for ELF common symbols (2.76 KB, patch)
2007-10-03 10:55 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Earnshaw 2007-07-17 12:20:32 UTC
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.
Comment 1 Richard Earnshaw 2007-07-17 12:23:50 UTC
        .comm foo, 32
#       .type foo, %common

uncomment the line to get an error.

nm -fsysv shows
foo                 |00000020|   C  |            OBJECT|00000020|     |*COM*

Comment 2 Nick Clifton 2007-10-03 10:55:49 UTC
Created attachment 2031 [details]
Accept STT_COMMON as a symbol type and use it for ELF common symbols
Comment 3 Nick Clifton 2007-10-03 11:01:25 UTC
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
Comment 4 H.J. Lu 2007-10-16 18:22:30 UTC
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.
Comment 5 Nick Clifton 2007-10-17 09:29:46 UTC
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
Comment 6 Alan Modra 2020-01-31 06:54:49 UTC
Fixed already, I think.