13

For example, I've seen _start as .global _start and .globl _start. It seems like I can just use them interchangeably. Is there any difference between the two?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Al Smith
  • 203
  • 2
  • 8
  • 14
    You forgot to mention which assembler you use. For the GNU assembler consult the [manual](https://sourceware.org/binutils/docs/as/Global.html) which says: _Both spellings are accepted, for compatibility with other assemblers._ So there is no difference. – Jester May 28 '18 at 14:21
  • 3
    I think `.global` might have been added later. Probably old versions of GAS only accept `.globl`. x86 asm code in glibc and Linux (the kernel) always uses `.globl`, IIRC. – Peter Cordes May 29 '18 at 01:00
  • @Jester Why is it a comment and not an answer? It is the answer, isn't it? – ZeZNiQ May 14 '21 at 18:05

1 Answers1

2

They are the same. In fact, the LLVM assembler in MCParser/AsmParser.cpp lexes them as DK_GLOBL and DK_GLOBAL

DirectiveKindMap[".globl"] = DK_GLOBL;
DirectiveKindMap[".global"] = DK_GLOBAL;

but then parses them as the same attribute.

case DK_GLOBL:
case DK_GLOBAL:
    return parseDirectiveSymbolAttribute(MCSA_Global);
Olsonist
  • 2,051
  • 1
  • 20
  • 35
  • 3
    Probably a good idea to also link the GAS documentation (https://sourceware.org/binutils/docs/as/Global.html) which says they're synonyms. LLVM's directive handling is basically aiming for GAS compatibility, I think. – Peter Cordes Apr 11 '22 at 04:23
  • 1
    `binutils` source also confirms that they're the same, although that source looks very different to the LLVM source code above. Both symbols are handled identically; by calling a function named `s_globl`: `{"global", s_globl, 0}, {"globl", s_globl, 0},` – AJM Aug 11 '22 at 15:37