Thread overview
Writing a small linux binary
Jan 12, 2015
NVolcz
Jan 12, 2015
ketmar
Jan 12, 2015
Mike
Jan 12, 2015
Paulo Pinto
Jan 12, 2015
Iain Buclaw
Jan 12, 2015
Paulo Pinto
January 12, 2015
Can this be done in D? How easy is it? What about the runtime?

https://www.reddit.com/r/programming/comments/2s1sgg/151byte_static_linux_binary_in_rust/

Best regards,
NVolcz
January 12, 2015
On Mon, 12 Jan 2015 05:59:35 +0000
NVolcz via Digitalmars-d <digitalmars-d@puremagic.com> wrote:

> Can this be done in D?
yes.

> How easy is it?
it depends of your experience and readyness to live without phobos and GC.

> What about the runtime?
you may need to write one which will include only functions your program requires.

p.s. i've not visited the link.


January 12, 2015
On Monday, 12 January 2015 at 05:59:36 UTC, NVolcz wrote:
> Can this be done in D? How easy is it? What about the runtime?
>
> https://www.reddit.com/r/programming/comments/2s1sgg/151byte_static_linux_binary_in_rust/
>

Here's a link to my 56 byte "Hello, World!" program for the ARM Cortex-M platform in D.  And, if I only used the string "Hello!" like the rust example, I believe it would be 47 bytes.

http://goo.gl/qWhpVX

Mike

January 12, 2015
On Monday, 12 January 2015 at 08:46:57 UTC, Mike wrote:
> On Monday, 12 January 2015 at 05:59:36 UTC, NVolcz wrote:
>> Can this be done in D? How easy is it? What about the runtime?
>>
>> https://www.reddit.com/r/programming/comments/2s1sgg/151byte_static_linux_binary_in_rust/
>>
>
> Here's a link to my 56 byte "Hello, World!" program for the ARM Cortex-M platform in D.  And, if I only used the string "Hello!" like the rust example, I believe it would be 47 bytes.
>
> http://goo.gl/qWhpVX
>
> Mike

Just posted the link to HN.

--
Paulo
January 12, 2015
On 12 January 2015 at 08:46, Mike via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On Monday, 12 January 2015 at 05:59:36 UTC, NVolcz wrote:
>>
>> Can this be done in D? How easy is it? What about the runtime?
>>
>>
>> https://www.reddit.com/r/programming/comments/2s1sgg/151byte_static_linux_binary_in_rust/
>>
>
> Here's a link to my 56 byte "Hello, World!" program for the ARM Cortex-M platform in D.  And, if I only used the string "Hello!" like the rust example, I believe it would be 47 bytes.
>
> http://goo.gl/qWhpVX
>
> Mike
>


Without performing any linker magic.

root@f6e559d2d853:~# cat > small.d << EOF
import core.stdc.stdio;
import core.stdc.stdlib;

extern(C) void main()
{
  printf("Hello!\n");
  exit(0);
}
EOF

root@f6e559d2d853:~# gdc -frelease -Os -nophoboslib -fno-emit-moduleinfo -nostdlib --entry=main small.d -lc -o small

root@f6e559d2d853:~# wc -c small
2488 small

root@f6e559d2d853:~# ./small
Hello!
January 12, 2015
On Monday, 12 January 2015 at 09:00:58 UTC, Iain Buclaw via Digitalmars-d wrote:
> On 12 January 2015 at 08:46, Mike via Digitalmars-d
> <digitalmars-d@puremagic.com> wrote:
>> On Monday, 12 January 2015 at 05:59:36 UTC, NVolcz wrote:
>>>
>>> Can this be done in D? How easy is it? What about the runtime?
>>>
>>>
>>> https://www.reddit.com/r/programming/comments/2s1sgg/151byte_static_linux_binary_in_rust/
>>>
>>
>> Here's a link to my 56 byte "Hello, World!" program for the ARM Cortex-M
>> platform in D.  And, if I only used the string "Hello!" like the rust
>> example, I believe it would be 47 bytes.
>>
>> http://goo.gl/qWhpVX
>>
>> Mike
>>
>
>
> Without performing any linker magic.
>
> root@f6e559d2d853:~# cat > small.d << EOF
> import core.stdc.stdio;
> import core.stdc.stdlib;
>
> extern(C) void main()
> {
>   printf("Hello!\n");
>   exit(0);
> }
> EOF
>
> root@f6e559d2d853:~# gdc -frelease -Os -nophoboslib
> -fno-emit-moduleinfo -nostdlib --entry=main small.d -lc -o small
>
> root@f6e559d2d853:~# wc -c small
> 2488 small
>
> root@f6e559d2d853:~# ./small
> Hello!

Would be considered linker magic to use _start(), write() and _exit() instead? :)

--
Paulo