What does the .globl directive do in assembly, and what happens to a symbol without it?
.globl name exports a symbol so the linker can resolve references to it from other object files; without it the symbol is local to its own file.
* The .globl directive exports a symbol for the linker to match across files; a symbol without it stays file-local like C static. *
When you compile multiple .c/.s files separately, each becomes an object file. The linker then stitches them together by matching up symbol names. A symbol only participates in that matching if it's marked global — otherwise it's invisible outside its own file.
.globl main # main is visible to the linker (and to the C runtime)
main:
...
This is the assembly equivalent of external linkage in C. A C function is global by default; marking it static makes it file-local — exactly the difference between having .globl and omitting it.
Common gotcha: If main is missing .globl, the C startup code can't find your entry point and the linker reports an undefined-reference error for main.
Go deeper:
GNU Assembler (Wikipedia) — what GAS is and how its output feeds the linker.
Using as — the GNU Assembler manual — the .globl/.global directive and symbol visibility in the manual.