Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Without life, Biology itself would be impossible.


devel / comp.lang.c / cc64 struct by value

SubjectAuthor
* cc64 struct by valuePaul Edwards
`* Re: cc64 struct by valueBart
 `* Re: cc64 struct by valuePaul Edwards
  `- Re: cc64 struct by valueBart

1
cc64 struct by value

<1eebe610-007e-49fe-bcb8-ba6e3fdf237fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28741&group=comp.lang.c#28741

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a9b:b0:412:2646:9995 with SMTP id s27-20020a05622a1a9b00b0041226469995mr269924qtc.10.1693863871516;
Mon, 04 Sep 2023 14:44:31 -0700 (PDT)
X-Received: by 2002:ac8:5b03:0:b0:410:a9dd:9fe4 with SMTP id
m3-20020ac85b03000000b00410a9dd9fe4mr268502qtw.1.1693863871130; Mon, 04 Sep
2023 14:44:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 4 Sep 2023 14:44:30 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=136.158.103.193; posting-account=CeHKkQoAAAAowY1GfiJYG55VVc0s1zaG
NNTP-Posting-Host: 136.158.103.193
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1eebe610-007e-49fe-bcb8-ba6e3fdf237fn@googlegroups.com>
Subject: cc64 struct by value
From: mutazi...@gmail.com (Paul Edwards)
Injection-Date: Mon, 04 Sep 2023 21:44:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4831
 by: Paul Edwards - Mon, 4 Sep 2023 21:44 UTC

Hi Bart or anyone else who might know.

It looks to me like when a struct is passed by value,
that it manages to get clobbered anyway.

C:\devel\pdos\pdas>pdas --oformat coff --64 -o ../pdpclib/x64supb.obj ../pdpclib/x64supb.asm
OVERLAP0 and
yyy A:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
yyy B:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0
overlap0 is:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
instruction types 0 is:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0

OVERLAP0 and
yyy A:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
yyy B:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
overlap0 is:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
instruction types 0 is:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Can you confirm that is the case and suggest any workaround?

Relevant code here:

https://sourceforge.net/p/pdos/gitcode/ci/master/tree/pdas/src

https://sourceforge.net/p/pdos/gitcode/ci/master/tree/cc64/cc64.c

Thanks. Paul.

C:\devel\pdos\pdas>git diff .
diff --git a/pdas/src/i386_as.c b/pdas/src/i386_as.c
index ae7a26c2..92cf1845 100644
--- a/pdas/src/i386_as.c
+++ b/pdas/src/i386_as.c
@@ -518,7 +518,22 @@ static struct operand_type operand_type_or (struct operand_type a, struct operan
static struct operand_type operand_type_and (struct operand_type a, struct operand_type b)
{
size_t i;
- +
+ printf("yyy A: \n");
+ {
+ for (i = 0; i < sizeof (a)/sizeof (unsigned int); i++) {
+ printf ("%d ", ((unsigned int *)&a)[i]);
+ }
+ printf ("\n");
+ }
+ printf("yyy B: \n");
+ {
+ for (i = 0; i < sizeof (b)/sizeof (unsigned int); i++) {
+ printf ("%d ", ((unsigned int *)&b)[i]);
+ }
+ printf ("\n");
+ }
+ for (i = 0; i < sizeof (a); i++) {
((unsigned char *)&a)[i] &= ((unsigned char *)&b)[i];
}
@@ -2506,8 +2521,32 @@ static int match_template (char mnemonic_suffix)
if (instruction.operands == 0) break;

matching_error = x86_error_operand_type_mismatch;
- +
+ /* Skip the first to prove that operand_type_and destroys instruction.types[0]. */
+ if (found_reverse_match == 0) {
+ found_reverse_match = 1;
+ continue;
+ }
+ printf ("OVERLAP0 and\n");
operand_type_overlap0 = operand_type_and (instruction.types[0], template->operand_types[0]);
+ printf("overlap0 is: \n");
+ {
+ size_t i;
+ for (i = 0; i < sizeof (operand_type_overlap0)/sizeof (unsigned int); i++) {
+ printf ("%d ", ((unsigned int *)&operand_type_overlap0)[i]);
+ }
+ printf ("\n");
+ }
+ printf("instruction types 0 is: \n");
+ {
+ size_t i;
+ unsigned int *p = (unsigned int *)&instruction.types[0];
+ for (i = 0; i < sizeof (operand_type_overlap0)/sizeof (unsigned int); i++) {
+ printf ("%d ", p[i]);
+ }
+ printf ("\n\n");
+ }
+ continue; /* To reduce where instruction.types[0] might change. */

switch (template->operands) {

diff --git a/pdas/src/i386_opc.h b/pdas/src/i386_opc.h
index 85b1e0f6..936fac65 100644
--- a/pdas/src/i386_opc.h
+++ b/pdas/src/i386_opc.h
@@ -10,7 +10,7 @@
*****************************************************************************/
#define MAX_OPERANDS 3

-#define GENERATOR_MACRO(a) unsigned int a : 1;
+#define GENERATOR_MACRO(a) unsigned int a;

#define GENERATOR_CPU_FLAGS_LIST \
GENERATOR_MACRO(cpu_186) \

C:\devel\pdos\pdas>

Re: cc64 struct by value

<ud5lb9$1l97p$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28743&group=comp.lang.c#28743

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: cc64 struct by value
Date: Mon, 4 Sep 2023 23:22:34 +0100
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <ud5lb9$1l97p$1@dont-email.me>
References: <1eebe610-007e-49fe-bcb8-ba6e3fdf237fn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Sep 2023 22:22:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="12c26e2becd6d1e0d07f8c2ea7e50a28";
logging-data="1746169"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NJag+iGpRkuseqGYnDcQ7EJWZSvBFCZg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:voQKXEzOA8HIgYkhlstFBJb0bDU=
In-Reply-To: <1eebe610-007e-49fe-bcb8-ba6e3fdf237fn@googlegroups.com>
 by: Bart - Mon, 4 Sep 2023 22:22 UTC

On 04/09/2023 22:44, Paul Edwards wrote:
> Hi Bart or anyone else who might know.
>
> It looks to me like when a struct is passed by value,
> that it manages to get clobbered anyway.

This is a bad bug in the cc64 (bcc) project. One of many reasons why I
withdrew the project and made it private only.

In this 2017 compiler, value-struct passing support was poor, but also
it wasn't that common then. Then libraries like Raylib started using it
extensively.

One problem is that on typical ABIs, structs are not really passed by
value, but by reference. So to emulate pass-by-value, you need to make a
copy and pass a reference to that copy.

In the test program below, fred() can modify the value of the caller's
struct.

---------------------------------------
#include <stdio.h>

typedef struct {int a[3];} S;

void fred(S x) {
x.a[1]=777;
}

int main(void) {
S x = {{10,20,30}};

fred(x);
printf("%d %d %d\n", x.a[0], x.a[1], x.a[2]);
} ---------------------------------------

There isn't really a workaround; the compiler needs to be fixed. If you
need this now in my example, you might change the fred(x) call to:

S temp;
fred(temp = x);

or maybe:

S temp = x;
fred(temp);

Re: cc64 struct by value

<5a7a0e3e-b1e7-43ae-9019-be544edf5977n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28745&group=comp.lang.c#28745

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1899:b0:412:2d71:70dd with SMTP id v25-20020a05622a189900b004122d7170ddmr272635qtc.5.1693867503674;
Mon, 04 Sep 2023 15:45:03 -0700 (PDT)
X-Received: by 2002:a63:8c16:0:b0:56f:8338:ebb3 with SMTP id
m22-20020a638c16000000b0056f8338ebb3mr2466421pgd.11.1693867503209; Mon, 04
Sep 2023 15:45:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 4 Sep 2023 15:45:02 -0700 (PDT)
In-Reply-To: <ud5lb9$1l97p$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=136.158.103.193; posting-account=CeHKkQoAAAAowY1GfiJYG55VVc0s1zaG
NNTP-Posting-Host: 136.158.103.193
References: <1eebe610-007e-49fe-bcb8-ba6e3fdf237fn@googlegroups.com> <ud5lb9$1l97p$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5a7a0e3e-b1e7-43ae-9019-be544edf5977n@googlegroups.com>
Subject: Re: cc64 struct by value
From: mutazi...@gmail.com (Paul Edwards)
Injection-Date: Mon, 04 Sep 2023 22:45:03 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Paul Edwards - Mon, 4 Sep 2023 22:45 UTC

On Tuesday, September 5, 2023 at 6:22:47 AM UTC+8, Bart wrote:

> In this 2017 compiler, value-struct passing support was poor, but also
> it wasn't that common then. Then libraries like Raylib started using it
> extensively.

It is interesting that this C90 feature was apparently only
used in anger (such that it caused an issue here) post-2017.

> One problem is that on typical ABIs, structs are not really passed by
> value, but by reference.

I see.

> There isn't really a workaround; the compiler needs to be fixed. If you
> need this now in my example, you might change the fred(x) call to:

I don't necessarily "need" things "now", but yes, I would like to
see if I can work around issues now.

> S temp;
> fred(temp = x);

Thanks. I went with this and it seems to be working.

C:\devel\pdos\pdas>git diff .
diff --git a/pdas/src/i386_as.c b/pdas/src/i386_as.c
index ae7a26c2..ddb87d53 100644
--- a/pdas/src/i386_as.c
+++ b/pdas/src/i386_as.c
@@ -2470,6 +2470,10 @@ static int match_template (char mnemonic_suffix)

for (template = current_templates->start; template < current_templates->end; template++) {
struct operand_type operand_type_overlap0, operand_type_overlap1;
+#ifdef __CC64__
+ struct operand_type temp;
+ #define operand_type_and(a, b) (operand_type_and)(temp = (a), (b))
+#endif
unsigned int size_match;

if (instruction.operands != template->operands) {

C:\devel\pdos\pdas>

BFN. Paul.

Re: cc64 struct by value

<ud5pf5$1lpe2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28748&group=comp.lang.c#28748

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: cc64 struct by value
Date: Tue, 5 Sep 2023 00:32:55 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <ud5pf5$1lpe2$1@dont-email.me>
References: <1eebe610-007e-49fe-bcb8-ba6e3fdf237fn@googlegroups.com>
<ud5lb9$1l97p$1@dont-email.me>
<5a7a0e3e-b1e7-43ae-9019-be544edf5977n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 4 Sep 2023 23:32:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="12c26e2becd6d1e0d07f8c2ea7e50a28";
logging-data="1762754"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Q69itXKrXw84RKJ4OAZ3G5G8OxeM1Dtg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:kqVcP8eKBZJNflwwbAI5foWLutM=
In-Reply-To: <5a7a0e3e-b1e7-43ae-9019-be544edf5977n@googlegroups.com>
 by: Bart - Mon, 4 Sep 2023 23:32 UTC

On 04/09/2023 23:45, Paul Edwards wrote:
> On Tuesday, September 5, 2023 at 6:22:47 AM UTC+8, Bart wrote:
>
>> In this 2017 compiler, value-struct passing support was poor, but also
>> it wasn't that common then. Then libraries like Raylib started using it
>> extensively.
>
> It is interesting that this C90 feature was apparently only
> used in anger (such that it caused an issue here) post-2017.

Actually I was thinking more about APIs. I'd used C APIs, mainly
Windows-related, since the mid-80s. Passing and returning structs by
value was rarely encountered, until I used Raylib.

But even Raylib didn't modify the passed structs that I recall.

(Interestingly, my own languages had had actual pass-by-value structs
and arrays for about 25 years, until I switched to Win ABI, but I never
used the feature.)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor