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!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Linker_Alias Date: Wed, 03 Jan 2018 21:59:08 +0000 Organization: A noiseless patient Spider Message-ID: References: <6042baa6-7743-48aa-8237-87181ab41a02@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="374867fda94719e6d8d0cf912deeb372"; logging-data="27099"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sqiYupxEBnVkpXHQatyjJ3AMHURZE6ak=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:TmkOqGzGElzM2Uz8gTXFlvuo0b0= sha1:s8tdvNN0Yvq14jkMz2wjjZEtd1k= Xref: reader02.eternal-september.org comp.lang.ada:49740 Date: 2018-01-03T21:59:08+00:00 List-Id: Jere writes: > I know this is more of a GNAT question than an Ada question > but was hoping someone else had some insight to this pragma. > > I am trying to use pragma Linker_Alias to set up a default > operation for an operation defined with pragma Weak_External. [...] > The intent is that GNAT links in a default operation unless > the client exports a procedure with the intended link name. > > The use case is for ZFP runtimes where I don't have access > to protected procedures. I want to supply a dummy ISR > unless the client decides to override it. > > I know GCC itself supports this (I tested it in another > language just to make sure), but I cannot figure out how > to get GNAT to support it. > > Am I setting up the pragma's wrong? I've tried a few different > combinations, but with no luck. > > I'm on Windows 10 using GNAT GPL 2017 (same problem on 2015 and 2016). On macOS with GCC8 it failed to link (symbol "target" missing). I never came across pragma Linker_Alias (and the description isn't easy to get my head round). I had a similar problem in Cortex GNAT RTS: the default was procedure HardFault_Handler with Export, Convention => Ada, External_Name => "HardFault_Handler"; pragma Weak_External (HardFault_Handler); procedure HardFault_Handler is begin loop null; end loop; end HardFault_Handler; and then, if required, override by providing a package containing procedure Handler with Export, Convention => Asm, External_Name => "HardFault_Handler"; pragma Machine_Attribute (Handler, "naked"); whose body works out which stack is in use and sets up for debugging. One thing that confused me for a while was that you have to ensure that the overriding package actually gets linked; my comment says -- Normally, we'd mark this unit as preelaborable, but that would -- mean that the binder-generated code wouldn't reference it, so -- it wouldn't get referenced at all (because the weak symbol in -- startup.o would satisfy the link). https://github.com/simonjwright/cortex-gnat-rts/blob/master/common/hardfault_handling.ads (and .adb).