

Hello from a libc-free world - ndesaulniers
https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_free

======
haberman
A related and somewhat more entertaining article along the same lines:
[http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...](http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html)

~~~
legedemon
When I read the article on Oracle's page, I was thinking of exactly this same
article. Any change they are written by the same person?

------
adr_
I wrote an actual libc-free "Hello World" program for Linux:
<http://codepad.org/rUckf7jR>

It should work as 32-bit or 64-bit and compile with clang or gcc. It compiles
to about 11 assembly instructions.

To produce a fairly small file:

    
    
        $ clang -nostdlib -O3 -o helloworld -m32 helloworld.c
        $ strip helloworld
        $ strip -R .note.gnu.build-id ./helloworld
        $ wc -c helloworld
        428 helloworld

------
csense
Why do people use the AT&T syntax for assembly language? It sucks and needs to
die [1] [2] [3]. I would support an effort to remove it from the GNU
toolchain.

[1] [http://blog.reverberate.org/2009/07/giving-up-on-at-style-
as...](http://blog.reverberate.org/2009/07/giving-up-on-at-style-assembler-
syntax.html)

[2] <https://news.ycombinator.com/item?id=5498967>

[3]
[http://forums.xkcd.com/viewtopic.php?f=40&t=19558](http://forums.xkcd.com/viewtopic.php?f=40&t=19558)

~~~
tjdetwiler
Lots of people learn on AT&T syntax and don't know Intel syntax.

~~~
maximilianburke
If you're going to be spending time writing/reading assembly there's a good
chance you'll need to refer to the architecture manuals and, for Intel, those
only use the Intel syntax. Matching the reference material I think should be
reason enough to move away from AT&T syntax.

------
jschneier00
The entire ksplice blog is fantastic for interesting lower level insights and
discussion.

Some personal favorites include:

[https://blogs.oracle.com/ksplice/entry/strace_the_sysadmin_s...](https://blogs.oracle.com/ksplice/entry/strace_the_sysadmin_s_microscope)

[https://blogs.oracle.com/ksplice/entry/attack_of_the_cosmic_...](https://blogs.oracle.com/ksplice/entry/attack_of_the_cosmic_rays1)

[https://blogs.oracle.com/ksplice/entry/much_ado_about_null_e...](https://blogs.oracle.com/ksplice/entry/much_ado_about_null_exploiting1)

EDIT: how do I format links nicely? markdown doesnt seem to work and help
doesnt mention links

~~~
ndesaulniers
I remember reading the cosmic rays article but did not know it was also
written by ksplice, neat! Also, I'm not sure how well HN supports markdown. I
was able to use asterisks to get italics, but not square braces followed by
parentheses for links. That was following github's cheat-sheet (go to github
and press 'm' to see the markdown cheat-sheet).

~~~
prodigal_erik
It doesn't, only paragraphs and emphasis and code samples.

<https://news.ycombinator.com/formatdoc>

------
networked
For a language with a C-like syntax that compiles into minimal x86 executables
check out W [1]. It was designed for use in a small, single-executable self-
hosting compiler targeting the HP 95LX family of early MS-DOS
"calculators"/PDAs [2] and hence has no equivalent of libc; instead it expects
you to code your own basic routines in assembly. I once wrote a bootable toy
application in it that ran on regular x86 desktops (a command-line interpreter
and calculator) and found the experience quite pleasant.

Here's a "Hello, World" in W:

    
    
        write := 0x8B55, 0x8BEC, 0x085E, 0x4E8B, 0x8B04, 0x0656, 0x00B8,
    	     0xCD40, 0x7321, 0x3102, 0x8BC0, 0x5DE5, 0x90C3
        
        _() :=
        {
            write(1, "Hello, World!\r\n", 15)
        }
    

[1] <http://www.vttoth.com/CMS/index.php/projects/49>

[2] <https://en.wikipedia.org/wiki/HP_200LX>

~~~
scott_s
You're not actually implementing your subroutines in assembly, but _machine
code_.

~~~
networked
Well, yes. I should have been more clear that it's a "bring your own
assembler" kind of deal. You have put the machine code in hexadecimal in the
final .W file before it's compiled. Back then I used a free early version of
Hiew [1] to assemble the subroutine code for my project but if I did it now
I'd either make some kind of a preprocessor to convert in-line assembly to
machine code before the source is fed to W.COM (the compiler's executable) or
modify the compiler itself to call an external assembler. You can do the
latter since the compiler's source code [2] is licensed under the GNU GPL.

[1] <http://www.hiew.ru/>

[2] ftp://gateway.vttoth.com/pub/w.zip

------
xal
Heh, kids these days. We needed to do that to even have a chance at competing
in 4k intro competitions.

~~~
Jare
Ah the joys of getting Watcom C to work with PMODE [1] before PMODE/W made it
easier.

[1] <http://en.wikipedia.org/wiki/PMODE>

~~~
limmeau
Why would one use PMODE with Watcom when Watcom comes with DOS/4GW?

~~~
Jare
Size, ability to have a single executable, requirement to display their
copyright, and probably a few technical ones I can't remember anymore; I
vaguely recall stuff about DOS4GW being more strict with certain CONFIG.SYS
and HIMEM settings, but it was almost 20 years ago. :)

------
whackedspinach
Is it still "Hello, world!" if that is never printed to the screen?

~~~
anvandare
Good point! Just add some inline-assembly to have it call write:

    
    
      int main()
      {
          char *str = "hello world\n";
          int len = 12;
          __asm__ ( "int $0x80"
                    :: "a" (4), "b" (1), "c" (str), "d" (len)
          );
          return 0;
      }

------
DanOWar
Part two:
[https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_fre...](https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_free1)

------
marshray
I once had an evening/weekend project to write C++ code on Windows without
linking to the C and C++ runtime libraries. It was a lot of fun and it gave me
some preparation for a next job that involved even more system-level stuff.

------
alok-g
Older discussion: <https://news.ycombinator.com/item?id=3158862>

~~~
ndesaulniers
Interesting, I thought HN would only give you a point for re-posting something
that had already been posted...

~~~
alok-g
Notice that the older discussion had a nominally different URL.

------
zimbatm
posted Mar 16, 2010

~~~
ndesaulniers
Sorry, I guess it's not "news." But the guidelines don't mention that it has
to be. And it's not really necrobumping since I'm not reopening an old thread,
just posting an article I read that I found really interesting, regardless of
its age.

From the guidelines:

"What to Submit

On-Topic: Anything that good hackers would find interesting. That includes
more than hacking and startups. If you had to reduce it to a sentence, the
answer might be: anything that gratifies one's intellectual curiosity."

------
MadMud
Could someone please explain to my how it is acceptable that oracle neends to
plant cookies for me tor read this?

