From: Szabolcs Nagy <nsz@port70.net> To: 王洪亮 <wanghongliang@loongson.cn> Cc: musl@lists.openwall.com Subject: Re: [musl] add loongarch64 port v3 Date: Sun, 29 May 2022 08:34:02 +0200 [thread overview] Message-ID: <20220529063402.GS1320090@port70.net> (raw) In-Reply-To: <07a1976c-2872-0e69-5602-7f5f055ef5ff@loongson.cn> * 王洪亮 <wanghongliang@loongson.cn> [2022-05-26 11:07:42 +0800]: > 在 2022/5/25 下午8:32, Rich Felker 写道: > > On Wed, May 25, 2022 at 06:08:23PM +0800, 王洪亮 wrote: > > > 在 2022/5/24 下午8:32, Rich Felker 写道: > > > > What we've been trying to say is that there are several cases, none of > > > > which seem to need it: > > > > > > > > 1. You create an object with declared type struct sigcontext. In this > > > > case, the flexible array member at the end is not present at all > > > > (because that's how C works) which means there's no extended > > > > context which needs additional alignment and probably also means > > > > this is not a usable way of creating sigcontext structs. > > > > > > > > 2. You malloc storage for the object with space for the flexible array > > > > member. In this case the allocation has alignment max_align_t and > > > > everything is fine. > I don't understand what is alignment max_align_t? I found the max_align_t > definition in musl,is this it? it is specified in iso c11. malloc aligns at least to this alignment. > > TYPEDEF struct { long long __ll; long double __ld; } max_align_t; > > I understand if FAM is not specified alignment,FAM is aligned according to > its type size,why is max_align_t? > > > > > > > > 3. You get the object from the kernel pushing it onto the stack in a > > > > signal frame. This is probably actually the only case the type is > > > > usable in, and of course it has whatever alignment the kernel gave > > > > it. > > > Specify the __attribute__((__aligned__(16))) in musl,is used to be > > > consistent with kernel.if I removed the __attribute__((__aligned__(16))), > > > there is a libc-test fail in pthread_cancel.exe.the reason is that the > > > offset of uc->uc_mcontext from the start of uc obtained in cancel_handler > > > is inconsistent with kernel pushing it onto the stack in a signal frame. > > > so I understand the __attribute__((__aligned__(16))) is necessary in musl. > > > > > > src/thread/pthread_cancel.c > > > > > > static void cancel_handler(int sig, siginfo_t *si, void *ctx) > > > { > > > pthread_t self = __pthread_self(); > > > ucontext_t *uc = ctx; > > > uintptr_t pc = uc->uc_mcontext.MC_PC; > > > ... > > > } > > > > > > musl/arch/loongarch64/bits/signal.h: > > > > > > typedef unsigned long greg_t, gregset_t[32]; > > > typedef struct sigcontext { > > > unsigned long pc; > > > gregset_t gregs; > > > unsigned int flags; > > > unsigned long extcontext[]; > > > }mcontext_t; > > > > > > linux/arch/loongarch/include/uapi/asm/sigcontext.h: > > > > > > struct sigcontext { > > > __u64 sc_pc; > > > __u64 sc_regs[32]; > > > __u32 sc_flags; > > > __u64 sc_extcontext[0] __attribute__((__aligned__(16))); > > > }; > > This is because ucontext_t is defined without explicit padding before > > uc_mcontext. Add "long __uc_pad;" or similar before it so that the > > offset is explicitly what it's supposed to be rather than a > > consequence ot overalignment. > > Add "long __uc_pad;" before uc_mcontext can resolve offset error, > why it is better than sc_extcontext[] __attribute__((__aligned__(16)))? > isn't it more direct to be consistent with kernel? the aligned attribute is not standard (iso c11 has _Alignas instead). the kernel does not care, but libc headers must work with all compilers and c language parsing tools, so if we can specify a struct with the same abi that the kernel wants but in a standard conform way, then we should do it that way. stating the padding explicitly is useful anyway when the exact layout of a type matters. it is not just about declaring the type but documenting the abi.
prev parent reply other threads:[~2022-05-29 6:34 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-05 3:21 王洪亮 2022-05-09 1:34 ` [musl] " 王洪亮 2022-05-11 13:37 ` Rich Felker 2022-05-11 16:08 ` Arnd Bergmann 2022-05-16 14:27 ` [musl] " Rich Felker 2022-05-21 6:38 ` 王洪亮 2022-05-21 8:22 ` Markus Wichmann 2022-05-24 9:08 ` 王洪亮 2022-05-24 12:32 ` Rich Felker 2022-05-25 10:08 ` 王洪亮 2022-05-25 12:32 ` Rich Felker 2022-05-26 3:07 ` 王洪亮 2022-05-29 6:34 ` Szabolcs Nagy [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220529063402.GS1320090@port70.net \ --to=nsz@port70.net \ --cc=musl@lists.openwall.com \ --cc=wanghongliang@loongson.cn \ --subject='Re: [musl] add loongarch64 port v3' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://git.vuxu.org/mirror/musl/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).