global directive
Last updated
Last updated
At the start of any assembly program, the global directive tells the assembler where the program starts from. By default, the assembler takes the label "_start" as the entry point.
However, if we want, we can define any other entry point as well. For example, here, I've dedfined the entry point "yolo." Here is how GDB breaks the binary's assembly:
So, we can see that the program's first instruction is xor rax,rax which is in the yolo label. I defined this label using "global" as the start point.
Further, I'll now remove the "global" directive and see how gdb takes it.
So, the entry point is still "_yolo" since this is the first instruction that the assembler encounters.
Now, I explicitly define global _start. Upon inspection, using "info files" command, I can find the entry point's memory address which is the start label
And if it is just _start and no other label before that, assembler defaults to that.
I also experimented by changing this label's name from _start as well to a custom name. Seeems like assembler is picking up whatever the first label is in .text section as the entry point
To test this, I added another symbol before _yolo in .text
Finally, when I givee global yolo as the directive but with bro section before that in .text, assembler still picks up _bro as the start point
Conclusion: "global _start" tells the assembler the entry point into the program. If "start" doesn't exist, it picks the first instruction in .text section as the entry point. If there are multiple labels in .text and global is given any other variable in text whose name is not "_start" then it still defaults to using first label as the entry point.