public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: caiyinyu <caiyinyu@loongson.cn>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>, libc-alpha@sourceware.org
Cc: "Xi Ruoyao" <xry111@xry111.site>,
	lixing@loongson.cn, wuxiaotian@loongson.cn,
	王洪虎 <wanghonghu@loongson.cn>
Subject: Re: [PATCH] LoongArch: Ensure consistency with kernel by using union for struct members in mcontext_t and ucontext_t.
Date: Thu, 6 Apr 2023 17:59:05 +0800	[thread overview]
Message-ID: <3dd3e520-b5f0-beee-86f3-965a5d3c9dc6@loongson.cn> (raw)
In-Reply-To: <ZCxgkznMvdobq/Bs@arm.com>


在 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 <iostream>

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 <iostream>
#include <features.h>

#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.


  reply	other threads:[~2023-04-06  9:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03 12:01 caiyinyu
2023-04-04 17:38 ` Szabolcs Nagy
2023-04-06  9:59   ` caiyinyu [this message]
2023-04-06 11:02     ` Szabolcs Nagy

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=3dd3e520-b5f0-beee-86f3-965a5d3c9dc6@loongson.cn \
    --to=caiyinyu@loongson.cn \
    --cc=libc-alpha@sourceware.org \
    --cc=lixing@loongson.cn \
    --cc=szabolcs.nagy@arm.com \
    --cc=wanghonghu@loongson.cn \
    --cc=wuxiaotian@loongson.cn \
    --cc=xry111@xry111.site \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).