From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Can I get rid of C libraries dependencies? Date: Thu, 17 Sep 2015 10:25:23 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <0dd03a38-391b-45bc-859c-4ed2c42452e3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 17 Sep 2015 10:25:23 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="da745e888d4a5182b5fda6212bbb0a63"; logging-data="18456"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7GCKz/D0r/ygsPTkd1XSy649AGxljmCc=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:KG7wlWtMFDxEj5WIE/6MAR23F24= Xref: news.eternal-september.org comp.lang.ada:27783 Date: 2015-09-17T10:25:23+00:00 List-Id: On Thu, 17 Sep 2015 01:13:47 -0700, Leff Ivanov wrote: > среда, 16 сентября 2015 г., 19:13:11 UTC+3 пользователь Simon Wright > написал: >> Leff Ivanov writes: >> >> > What I want to achive is a tiny 2kb binary executable >> >> Can you tell us a little more about why you need to do this, what OS >> you're using ... > > I'm using windows and want to write tiny tools in Ada like I can write > one in C/C++ using -nostdlib flag and directly linking to OS specific > libraries. The same can be applied to Linux and Mac OSX as well, but > currently I'm focusing on Windows. > > If I do "gnatmake -a -f -nostdlib main.adb" I can see that GNAT actually > recompiles a lot of stuff from RTS, like a-except.adb, > s-secsta.abd and etc. So the No_Run_Time pragma cuts off only a part of > Ada RTS, but leaves the rest. > > Gnatlink tool with -nostdlib returns a lot of undefined references to C > code, which I want to get rid off. It seems that mostly it is functions > that implements exceptions, like _Unwind_SjLj_Register, > __gnat_personality_sj0 and etc. There are pragmas to restrict the use of exceptions : these should reduce the undefined references. > Undefined references to stuff like memmove and memcmp I can simply fix > by linking directly with libmsvcrt.a, so theese functions would be taked > from standard windows msvcrt.dll library. But there's also undefined > reference to __chkstk_ms, this function seem to check if the stack is > full. One way is to specify your own RTS, with the "--RTS=path/to/rts" option. Then you would need to create your own RTS, which in this case would be your wrapper that handles anything you can't link directly like memcpy etc. You can get a handle on how this works by studying the AVR-Ada microcontroller port, which is quite capable of generating executables down to a couple of hundred bytes. -- Brian