Hacker News new | past | comments | ask | show | jobs | submit login
Linux x86 Program Start Up (dbp-consulting.com)
143 points by bluetomcat on Dec 12, 2014 | hide | past | favorite | 30 comments



Coming from DOS/Windows the amount of... extra cruft that gets linked into a Linux binary by default seems rather excessive. The equivalent startup code in Windows for a C program doesn't involve constructors or destructors, for one thing. From the entry point, there's a total of ~7 functions called in the default stub - most of them for parsing the environment variables and creating argc/argv, and for programs that don't need that it's quite easy to eliminate those too.

(The whole ELF/dynamic linking system is another thing that has always seemed overly complex to me, compared to PE/DLLs.)


But Windows still supports constructors and destructors, right? I don't understand how it eliminate the complexity.

Do you mean that the windows equivalent of _start is nested less deeply and with more reasonable naming conventions?


On the other side of the spectrum, a tiny ELF executable is possible at 45 bytes: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...

Previous discussion: https://news.ycombinator.com/item?id=5016434


A different take on the same matter: http://www.bottomupcs.com/starting_a_process.html


I posted this the last time a similar article came up and a couple people seemed interested. I'm still trying to gauge whether anyone would be interested in a podcast about this kind of stuff. I've started putting together notes for this podcast here: https://docs.google.com/document/d/1Nn01yDS5PkiegHq4Oxz43xUQ...


Anyone got similar article for windows?


This appears to only be about userland stuff. Would be nice to explain what "execve" does.


It's a hack left over from the early days when AT&T UNIX became BSD. Under pre-BSD UNIX systems, a program was started by forking a new process, which meant sharing the code and copying the data. Then the new process did an exec, which loaded a new code segment and wiped the data segment that had just been copied. Copying the data segment and immediately overwriting it was inefficient, so several new flavors of "exec" were developed to get around that.

There probably should have just been a "run" call, which started a subprocess given the indicated executable. Some UNIX-like operating systems have that. It has the nice property that it scales to clusters; there's no reason a subprocess can't run on another machine. QNX, for example, supports that.


> Copying the data segment and immediately overwriting it was inefficient, so several new flavors of "exec" were developed to get around that.

The several different flavors of exec are just convenience functions that lead to an execve syscall (execl* makes the vector out of some of its args; exec*p searches the path first, etc). Maybe you're thinking of vfork (a restricted fork), which seems to have gone away about when copy-on-write came in.


Right.


> executes the program pointed to by filename[1]

[1] http://linux.die.net/man/2/execve

man pages are your friend ;P

(I think they assume if you are doing this level of debugging, you are familiar with the typical linux sys calls, and/or know where to look-up more information about them)


I know what execve does. Hypothetically, someone may be able to find out the programmer-visible interface (through this man page) without actually knowing what is going on in the kernel when it happens (allocating memory to the process, paging in the necessary parts of it, adding it to the scheduler's queue, ...).


This looks like a fantastic resource, but I was off put by the (albeit tongue-in-cheek) 'RMUVI - Real Men Use VI' line in the article.


Because of the "men", because of the "vi", because of the "real", or because it's a jab at the readership?

Some time ago, I would have just assumed you were an emacs user, but these days there's a much larger diversity of people on the internet, who get offended by very many things.


I'm not the OP and I wouldn't necessarily say I'm "offended" by it, but it's kinda gross and I dislike it, especially in a context of wanting more diversity in my field. Would the world be a tiny bit better without that line? I think so.


It's an old riff on a book called "Real Men don't Eat Quiche" https://en.wikipedia.org/wiki/Real_Men_Don%27t_Eat_Quiche#Cu... which is a 1982 book that poked fun at hyperbolically conservative masculinity.


For the people who prefer to bikeshed around gender issues and don't know their history of programming languages: this is not just a pun on that book, but also on the essay "Real Programmers Don't Use Pascal" published in Datamation magazine in 1983. Which is by the way correct in pointing out that Real Men use neither Vi nor Emacs, but TECO. Oh yeah, and Real Man is a gender-neutral title in this context, like "fireman".


Call me a fireman and I’ll sock you in the nose. :)

We prefer “firefighter.”


There's not one context here.


That's not my reading of this use. The title of the 1982 book is using a silly statement to poke fun at the concept of masculinity. The jab in this article reads to me as accepting the concept of masculinity at face-value, and using it to poke fun at something in technology.


Went down the rabbit hole a bit (thanks Google) and found this thread from 2003 where someone said "real men use vi". https://www.redhat.com/archives/redhat-install-list/2003-Jul... I take it to mean real men do difficult things for no reason, which is not really a positive thing. A 2008 article updated the phrase to "real men and women use vi", still as hyperbole. http://www.terminally-incoherent.com/blog/2008/10/01/vim-tip... I guess the posted article didn't get the memo and still used the men-only version in 2011. But I guess you're right about this particular article, it's too easy to read it "straight".


It's a wonderful article about how low level assembly and C programs work on linux, and somehow HN gets caught up on a single intended-to-be-funny hyperbole, effectively turning it into a gender debate...


I think you're reading way too deep into this.


It might as well say "Real hackers use vi", "Real programmers use vi", or whatever. I do not see why it needs to be gender related.

The author should write whatever he pleases. But I believe it would be proper to use a language directed to a broader audience when writing a public blog post. I also believe that the author was trying to be funny and had no bad intents what so ever, but either way these tiny things matter if we ever want to see diversity in our field.

I would also like to add that your argumentation is quite unpleasant to me. I read it as you believe that diversity is this annoying thing that destroys the good ol' "all dude internet". Would you care to clarify what you meant?


I meant that the diversity makes it annoying because things that were good jokes suddenly turn ugly. So I do have to ask what is it that is not ok now. Because alright - not everything is ok, but I'm also sure that not everything is not-ok neither. Because if everything is not-ok, then nothing is ok and the only thing left for me to do is write in pure logic, probably in some language like lojban.

Tomorrow I'll write "real hackers use vi" and someone who has never programmed and has no interest in it will correct me that they're offended - they like the article, but don't self-identify as a hacker, so my usage would offend them. That's fine, I can use other words and people can only get offended at a finite set of them, but I do need to be told where my mistake is.


What "argumentation"? I see a question and an explanation of the question with no commentary whatsoever.


That's your take on the matter. I would like to hear Red Sonja's stance.

Clarifucation: She is a true knight, not a toy, and embodies all the knightly virtues. This included "hoher muot", of which there isn't enough of going round of that.


> I would also like to add that your argumentation is quite unpleasant to me. I read it as you believe that diversity is this annoying thing that destroys the good ol' "all dude internet".

So you're saying that men (read: dudes) can't be offended by this, also? That insults me.

Seriously though: "real men" phrases are often used in a serious way to try to police men's behaviour (you probably know this already, but anyway). So I, as a man, often feel queasy about "real men" quips. But real men aren't supposed to feel uneasy about such things, so I don't know.. ;)

I don't personally feel uneasy about this: it feels like satire that plays on the old trope of "real men do <thing that is hard, often unnecessarily so>", and all over "trivial" things like text editors. I can see how some people might be offended by the phrase, though. I'm just talking for myself here.

(I hope no vi users were offended by this post.)


Real men don't get insulted about real men posts.


Exactly ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: