Skip to content

[MC assembler] .globl does not emit symbol if unreferenced #9664

@DimitryAndric

Description

@DimitryAndric
Bugzilla Link 9292
Resolution FIXED
Resolved on Feb 23, 2011 14:24
Version trunk
OS All
CC @pwo

Extended Description

It looks like MC does not emit a global symbol into the destination
object file for a .globl directive, if the object is not referenced.

This is an unwanted optimization, since e.g. module loaders can depend
on specific symbols to always be available, so they use .globl to force
the linker to emit the symbol.

This substantially differs from GNU as's behaviour. For example,
assemble the following sample file with GNU as and clang:

.globl foo
.globl bar
mov %eax,bar

Running "readelf -s" over the object file that GNU as produces gives:

Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 SECTION LOCAL DEFAULT 1
2: 00000000 0 SECTION LOCAL DEFAULT 3
3: 00000000 0 SECTION LOCAL DEFAULT 4
4: 00000000 0 NOTYPE GLOBAL DEFAULT UND foo
5: 00000000 0 NOTYPE GLOBAL DEFAULT UND bar

Running "readelf -s" over the object file that GNU as produces gives:

Symbol table '.symtab' contains 5 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 SECTION LOCAL DEFAULT 1
2: 00000000 0 SECTION LOCAL DEFAULT 2
3: 00000000 0 SECTION LOCAL DEFAULT 3
4: 00000000 0 NOTYPE GLOBAL DEFAULT UND bar

MC should not remove the 'foo' symbol from the table here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions