13 ms·
A general overview of what happens before main() (2019)
- chmaynard 4y agoA minor quibble: the Mac operating system is no longer called OS X. The name changed to macOS in 2016, to align with the branding of Apple's other operating systems.
- schaefer 4y agoThat ex X still has us perplexed.
- c1yd3i 4y agoI'd just like to interject for a moment. What you're referring to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called "Linux", and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called "Linux" distributions are really distributions of GNU/Linux.
- wrycoder 4y agoIf Stallman had not written gcc, gdb, his version of emacs, the basic gnu utils, and, most importantly, the GPL, there would probably be no "Linux". Torvalds would have had to write a complete OS, and he probably would have got a job and a life before he accomplished that. It's too bad RMS got sidetracked with Hurd. But, the GNU system now runs with several kernels - the Linux kernel is just the most developed and best known one.
- planckscnst 4y agoThere are also operating systems using Linux that have no GNU at all. So it doesn't bother me at all when someone calls it Linux, and I'll continue to call it that myself unless there is additional context needed. Even then, I'd probably just reference specific GNU tools since there are other userspace tools on the system that are also necessary, but are not GNU. https://www.glaucuslinux.org/ https://www.glaucuslinux.org/ https://www.alpinelinux.org/ https://www.alpinelinux.org/
- mistrial9 4y agomarketing!
- thebitstick 4y agoI'd just like to interject for a moment. What you're referring to as macOS, is in fact, Darwin/macOS, or as I've recently taken to calling it, Darwin plus macOS. Darwin is not an operating system unto itself, but rather another free component of a fully functioning Unix system made useful by the BSD corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the Darwin system every day, without realizing it. Through a peculiar turn of events, the version of Darwin which is widely used today is often called "macOS", and many of its users are not aware that it is basically the Darwin system, developed by Next Computer. There really is a macOS, and these people are using it, but it is just a part of the system they use. XNU is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Darwin is normally used in combination with the macOS operating system: the whole system is basically Darwin with macOS added, or Darwin/macOS. All the so-called "macOS" versions are really versions of Darwin/macOS. --- Apple's engineers still refer to the OS as Mac OS X. Ventura is technically 10.18, despite the 13 major number in their marketing.
- chmaynard 4y agoYour comment, probably meant as satire, adds nothing of value to the discussion and invites a pointless debate about naming.
- pessimizer 4y agoIts parent was even more pedantic.
- deleted 4y ago[deleted]
- jorl17 4y agoIt is satire. It is a spin on a famous quote by Richard Matthew Stallman (RMS) about Linux (or "GNU/Linux").
- 4y ago
- wrycoder 4y agoprevious: https://news.ycombinator.com/item?id=16995811 https://news.ycombinator.com/item?id=16995811
- anthk 4y ago"nm" it's your friend here.
- saagarjha 4y ago> For example, OS X only has dynamically linked applications Statically linked code is permissible on Intel.
- mbeddedartistry 4y agoPlease provide a source for a statically linked application on MacOS, Intel or otherwise. When I wrote this article, Apple's own documentation said it was not supported. libSystem is also only provided as a dynamic library.
- p1necone 4y agoI thought "statically linked" just meant that all of the dependency binaries were rolled into the main executable at build time - how could macOS even stop you doing that? I assume my understanding of static linking is too simplistic though.
- saagarjha 4y agoOne dependency would be libc, which is typically how you would call into the OS using system calls. macOS has not typically supported a stable interface for these.
- johncolanduoni 4y agoOn some OSes (Linux and macOS for example) a dynamically linked executable specifies the runtime linker as its “interpreter”, and the runtime linker contains the initial entry point that the kernel starts the process’s execution from. A statically linked executable is then one that doesn’t specify any interpreter at all, and which directly receives control from the kernel. This distinction is related to but not the same as statically or dynamically linking an individual dependency; only if all dependencies are statically linked can an executable then be statically linked.
- saagarjha 4y agohttps://news.ycombinator.com/item?id=23673014 https://news.ycombinator.com/item?id=23673014
- not_a_sw_dork 4y ago[dead]
- loic-sharma 4y agoRelated, how to print "Hello world" without libc: https://www.youtube.com/watch?v=b9OJYMFpHRU&ab_channel=RubberDuckEng https://www.youtube.com/watch?v=b9OJYMFpHRU&ab_channel=Rubbe...
- adolph 4y agoAt 7:44 they go into the “magic numbers” used to define kernel syscalls like how Cosmopolitan [0] uses for building things like RedBean [1]. 0. https://github.com/jart/cosmopolitan https://github.com/jart/cosmopolitan 1. https://redbean.dev/ https://redbean.dev/
- olalonde 4y agoRelated, Rust's main(): https://github.com/rust-lang/rust/blob/1.62.0/library/std/src/rt.rs#L138 https://github.com/rust-lang/rust/blob/1.62.0/library/std/sr...
- pornel 4y agowith a twist that officially Rust doesn't have "life before main()". There's no user code running before main(). There are no static initializers with run-time constructors like C++ SIOF.
- jart 4y agoIf you want a Blinkenlights visualization of what happens from BIOS boot to main() then watch the second video under this heading: https://justine.lol/sectorlisp2/#emulation https://justine.lol/sectorlisp2/#emulation
- asveikau 4y agoIt says _start (crt0.o) comes from libc. But note, if you run nm on a binary you can see _start is part of the binary, not libc.so.
- naniwaduni 4y agoThe "libc" is more than libc.so. Your system headers, for example, must be shipped with your libc, even though everything that would change if you replace them with something nonsensical would be in "your" binary, not in libc.so. libc functions don't stop coming from the libc if you statically link them. A C runtime is often provided by the same project as the C standard library (the other viable option is to have it provided by the compiler project).
- asveikau 4y ago> Your system headers, for example, must be shipped with your libc, Not all. Typically stdarg.h is not. On Linux, <sys/*> is not.
- mbeddedartistry 4y agoIt says "usually". It varies! But, in general, the libc implementations I have looked at handle this. This includes Newlib, glibc (they call it start.s), picolibc, musl (crt1), and my own libc. The presence in your binary only means that crt0.o was statically linked (may be an expectation of the loader on your system). If you linked against a static libc, you would also see those symbols as part of the binary.
- asveikau 4y agoI think your last paragraph is wrong. crt0.o is static even when linking to libc.so dynamically. The ELF format has something in the headers for an entry point which will point at _start in your own binary, not in libc.so. I'm pretty sure it works that way on windows too, but they call the symbol mainCRTStartup or some such.
- 4y ago
- madog 4y agoAlso see the "From Zero to main()" series: https://interrupt.memfault.com/blog/zero-to-main-1 https://interrupt.memfault.com/blog/zero-to-main-1