From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id A088D3858D3C for ; Mon, 17 Jan 2022 18:55:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A088D3858D3C Received: by mail-pj1-x102c.google.com with SMTP id q30-20020a17090a752100b001b49f65ff61so598215pjk.4 for ; Mon, 17 Jan 2022 10:55:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NKcnkuBzJt4fFvxMt73W+84yAGMe41sWDMXnLLpk8vc=; b=wHR+dSTEwXuUADsKPDsgzfzi735XwRxdjZUBt0y7JrD/2jlrVX3XKaFubD3WreR0/v SAFdZ1j8NXln+hGwBWSukarYQZCr6a3f7n5BPSOsHIiCLxrMsqIirWeP0NK6lvzYCaAF oMyL6JB5+wf0LkTcpi3aadj1tHMfgYFUJExqOhPvMPD/oI7dymKTT6CeIsHWdSnFmxuY M8u6kdV50PqrpRs0U2EKmwetcnikv4gDmEZeJdsY1pAixXnKeitirLk5mMzswpISyYre 4bC4Lv40FBOivCE+ILAWYL8DGudNuHHj4wVBBaiXDBUShKLslueZp3RbrN+BAHDOdNWB do7g== X-Gm-Message-State: AOAM530WVi1z0jzxai2ohgSYdZuzfTbJJtRYn4sdEYPRS/pzzChdjv2y oAdrXrvj32JIf7NmU1Gk1NMrj2KJTAz5AVu4pFU= X-Google-Smtp-Source: ABdhPJyu9qXHQcHcNFyF1dHrc1GtJNAqjotL15NSJyUyudDmsgJIA/Wqc90eXWqhPG5LZReFXhqbkBAZbQQFNXnviik= X-Received: by 2002:a17:903:1c4:b0:14a:555c:adc0 with SMTP id e4-20020a17090301c400b0014a555cadc0mr23573697plh.101.1642445752472; Mon, 17 Jan 2022 10:55:52 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Mon, 17 Jan 2022 10:55:16 -0800 Message-ID: Subject: Re: [Exception Handling] Why does frame unwind label have static alignment 4? To: Joseph Faulls Cc: "gcc@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3021.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jan 2022 18:55:55 -0000 On Mon, Jan 17, 2022 at 9:24 AM Joseph Faulls wrote: > > Hello all, > > Small disclaimer of being new to EH, but I have come across a problem that seems quite fundamental to EH frame registry. I am targeting riscv64, but I believe the problem to be entirely platform agnostic. > > When using EH frame registry, a label is put at the beginning of the frame unwind info to register and deregister frames: > > libgcc/crtstuff.c: > > STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[] > > __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4))) > > This is then populated with struct dwarf_fde: > > libgcc/unwind-dw2-fde.h: > > struct dwarf_fde > > { > > uword length; > > sword CIE_delta; > > unsigned char pc_begin[]; > > } __attribute__ ((packed, aligned (__alignof__ (void *)))); > > The trouble is that the __EH_FRAME_BEGIN__ has alignment 4, whereas the struct dwarf_fde has alignment of void*. When targeting 64-bit, these values are not the same. > It is this that is causing 4 bytes of padding. This is the disassembly of a simple program targeting riscv64 that throws an exception: > > 22954 000000000000e324 <__EH_FRAME_BEGIN__>: > > e324: 0000 unimp > > e326: 0000 unimp > > e328: 0010 0x10 > > e32a: 0000 unimp > > e32c: 0000 unimp > > e32e: 0000 unimp > > e330: 00527a03 0x527a03 > > It is this that causes __register_frame_info_bases to fall flat on its face: > > Libgcc/crtstuff.c in function frame_dummy: > > __register_frame_info (__EH_FRAME_BEGIN__, &object); > > libgcc/unwind-dw2-fde.c > > void > > __register_frame_info_bases (const void *begin, struct object *ob, > > void *tbase, void *dbase) > > { > > /* If .eh_frame is empty, don't register at all. */ > > if ((const uword *) begin == 0 || *(const uword *) begin == 0) > > return; > > ... > > void > > __register_frame_info (const void *begin, struct object *ob) > > { > > __register_frame_info_bases (begin, ob, 0, 0); > > } > > This means no EH frames are ever registered, and so exceptions cannot be handled! > > So, why does __EH_FRAME_BEGIN__ have alignment 4 and not of __alignof__ (void *) ? Is this a bug? > > Thanks, > Joe This is: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27576 -- H.J.