From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id C03ED3858D32 for ; Thu, 6 Apr 2023 09:59:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C03ED3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.20.4.187]) by gateway (Coremail) with SMTP id _____8Cxjdrqly5kCTwXAA--.24681S3; Thu, 06 Apr 2023 17:59:07 +0800 (CST) Received: from [10.20.4.187] (unknown [10.20.4.187]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxIL_ply5kyw4XAA--.57060S3; Thu, 06 Apr 2023 17:59:06 +0800 (CST) From: caiyinyu Subject: Re: [PATCH] LoongArch: Ensure consistency with kernel by using union for struct members in mcontext_t and ucontext_t. To: Szabolcs Nagy , libc-alpha@sourceware.org Cc: Xi Ruoyao , lixing@loongson.cn, wuxiaotian@loongson.cn, =?UTF-8?B?546L5rSq6JmO?= References: <20230403120153.3332463-1-caiyinyu@loongson.cn> Message-ID: <3dd3e520-b5f0-beee-86f3-965a5d3c9dc6@loongson.cn> Date: Thu, 6 Apr 2023 17:59:05 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8AxIL_ply5kyw4XAA--.57060S3 X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxZF4rZr1rWFyUtFy5KF15urg_yoW5tr4xpF y0k3WFkrZrJ3ZY9ryUAw4jq343CryrJw1UGFy2kFy7A345tFn2qa4SvrWY9rn8WrW8WFWY vw45tryDZFy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earn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 在 2023/4/5 上午1:38, Szabolcs Nagy 写道: > The 04/03/2023 20:01, caiyinyu wrote: >> During the construction of the LoongArch Alpine system, >> we found that there is an inconsistency in the member >> names of mcontext_t and ucontext_t between musl and glibc, >> which can cause compilation errors. After testing, we decided >> to use union to keep these member names consistency. > there is no musl api compat requirement at the moment (the musl > loongarch port is not committed yet so surely that can be > changed to be consistent). We want to ensure that the structure member names in mcontext_t are consistent with the kernel (like other architectures) before submitting LoongArch musl (Currently under development) to the upstream community. This will allow for consistency in the structure member names across musl, glibc, and the kernel for related structures. > there is an api difference between glibc and linux uapi headers. > i personally don't think this is an issue. (the c abi must match > but struct sigcontext and mcontext_t are not used interchangably > in code. the c++ mangling abi is different even after your patch) I am currently facing some confusion. As far as I know, in C++, the member names of a struct or union are not subject to mangling. Mangling is only applied to the names of C++ entities such as functions, variables, classes, and namespaces. The member names of a struct or union are simply a part of the struct or union, and their names are not encoded or modified. Therefore, even if the member names of a struct or union are duplicated in different translation units, they will not be subject to mangling since they are different symbols. could you please provide a more detailed explanation about this issue? BTW, I have written a test case[1] and the result is as expected: The symbol name of function cyyprint which takes mcontext_t as args after C++ mangling are all _Z8cyyprint10mcontext_t. [1] compiled with  g++ tst1/2.cpp -shared -o tst1/2.so and nm tst1/2.so | grep cyy   ➜ cat tst1.cpp #include typedef struct mcontext_t {   unsigned long long __pc;   unsigned long long __gregs[32];   unsigned int __flags;   unsigned long long __extcontext[0] __attribute__((__aligned__(16))); } mcontext_t; void cyyprint(mcontext_t mx) { std::cout << mx.__pc << std::endl; }   ➜ cat tst2.cpp #include #include #ifdef __USE_MISC #define __ctx(fld) fld #else #define __ctx(fld) __##fld #endif typedef struct mcontext_t {   union {     struct {       unsigned long long __ctx(sc_pc);       unsigned long long __ctx(sc_regs)[32];       unsigned int __ctx(sc_flags);       unsigned long long __ctx(sc_extcontext)[0] __attribute__((__aligned__(16)));     };     struct {       unsigned long long __pc;       unsigned long long __gregs[32];       unsigned int __flags;       unsigned long long __extcontext[0] __attribute__((__aligned__(16)));     };   }; } mcontext_t; void cyyprint(mcontext_t mx) { std::cout << mx.__pc << std::endl; } > there is also a difference in ucontext compared to other targets: > they have uc_flags field while loongarch has __uc_flags. i don't > know if this may cause a portability issue. > > in any case the commit message does not do a good job describing > the reasoning.