Re: [Interest] Void pointers for Mac ARM

2023-06-20 Thread Thiago Macieira
On Tuesday, 20 June 2023 17:46:04 PDT Thiago Macieira wrote:
> On Tuesday, 20 June 2023 15:50:16 PDT Volker Hilsheimer via Interest wrote:
> > Either way, it would perhaps help to boil all this down to some minimal
> > code; you have a 2-byte aligned struct that you cast to and from void *,
> > this should be reproducible with small bit of code. And if you have that,
> > then comparing the assembly you get out of your compiler when targeting
> > Intel vs ARM might give some hints.
> 
> I'm pretty sure he's going to find out that the problem is not the casting,
> but elsewhere. The explanation currently doesn't make sense.

Proof that it's bitwise equivalent: https://godbolt.org/z/zc1vqh9cs

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-20 Thread Thiago Macieira
On Tuesday, 20 June 2023 15:50:16 PDT Volker Hilsheimer via Interest wrote:
> Either way, it would perhaps help to boil all this down to some minimal
> code; you have a 2-byte aligned struct that you cast to and from void *,
> this should be reproducible with small bit of code. And if you have that,
> then comparing the assembly you get out of your compiler when targeting
> Intel vs ARM might give some hints.

I'm pretty sure he's going to find out that the problem is not the casting, but 
elsewhere. The explanation currently doesn't make sense.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-20 Thread Volker Hilsheimer via Interest
(bringing this back to the original thread rather than the digest)

On 20 Jun 2023, at 14:54, Turtle Creek Software  wrote:
On 19 Jun 2023, at 17:30, Thiago Macieira  wrote:

On Monday, 19 June 2023 04:13:51 PDT Turtle Creek Software wrote:
The debugger showed the correct address but failed to cast a
parameter.

Can the ARM compiler handle #pragma pack (2) ?

What does this have to do with casting? It would really help if you gave exact
error messages. That includes warnings about ignored / unrecognised pragmas.

Anyway, why do you want #pragma produce_slow_memory_accesses?



Our code has structs that were set up in 16-bit processor days, and it uses an 
object database library that probably started for 8-bit.  Most structs were 
easy to revise for 4 and 8 byte alignments, but some parse data from disk. 
Those are the ones that get #pragma pack (2).  Any speed hit is tiny compared 
to disk access time.

We still need those old structs for a one-time file conversion of user data 
that may date back to the 90s. The code reads old structs, then writes newer 
ones with modern alignment. Sometimes arrays of them.

It worked fine in Qt5.  In Qt6 for ARM, 2-byte aligned structs mostly work, but 
if they go through a void pointer they don't cast back properly.  No specific 
system error, just our code sanity-checking and reporting the nullptr.

There's only a few places where we use function pointers with void parameters.  
They are hard to debug so it's fine to rewrite the last of them.

But that database library also loses structs when coming back from (the) void. 
It also worked in Qt5, but breaks for Qt6 on ARM. Their code is a nightmare, 
and we only need it once to read old files.  A rewrite would take years.

Does that make sense?

We haven't built with Qt6 for Windows yet but will do that soon. It may help 
narrow down where the problem lies.


I’m trying to understand what the differences are between “works” and “doesn’t 
work”. You have both Qt 5 vs Qt 6, and you have Intel vs ARM macs. So far you 
are saying that it works with Qt 5 on Intel, and that it doesn’t work with Qt 6 
on ARM. Do things work with Qt 6 on Intel macs? Do things work with Qt 5 on 
ARM? Are you building with the same toolchain versions, or are the clang 
versions different?

You’re also saying that this is all plain C/C++ code.

I’m not quite seeing yet what role Qt is playing in this - and maybe it doesn’t 
have any, in which case it’s still fine to consult this mailing list of course, 
but it would help to get this clarified :)

Either way, it would perhaps help to boil all this down to some minimal code; 
you have a 2-byte aligned struct that you cast to and from void *, this should 
be reproducible with small bit of code. And if you have that, then comparing 
the assembly you get out of your compiler when targeting Intel vs ARM might 
give some hints.


Volker

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-19 Thread Thiago Macieira
On Monday, 19 June 2023 04:13:51 PDT Turtle Creek Software wrote:
> The debugger showed the correct address but failed to cast a
> parameter.
> 
> Can the ARM compiler handle #pragma pack (2) ?

What does this have to do with casting? It would really help if you gave exact 
error messages. That includes warnings about ignored / unrecognised pragmas.

Anyway, why do you want #pragma produce_slow_memory_accesses?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-19 Thread coroberti
Sorry, no knowledge about the pragma and how it's handled by clang.

I'd make it all 8-bytes aligned on 64-bit.

Kind regards,
Robert Iakobashvili


On Mon, Jun 19, 2023 at 2:14 PM Turtle Creek Software
 wrote:
>
> Alignment is definitely possible.  There was a similar problem earlier in 
> execution, and that had pointers to 2-byte aligned structs.
> We just rewrote the ugly void* code rather than try to diagnose it further.  
> The debugger showed the correct address but failed to cast a parameter.
>
> Can the ARM compiler handle #pragma pack (2) ?
>
> Thanks,
> Casey McDermott
> TurtleSoft.com
>
> On Mon, Jun 19, 2023 at 2:50 AM coroberti  wrote:
>>
>> On Sat, Jun 17, 2023 at 8:12 PM Turtle Creek Software
>>  wrote:
>> >
>> > Our app contains some old C-ish C++ code from an early 90's database 
>> > called NeoAccess. It often uses function pointers with void pointers as 
>> > parameters.  Their code works OK for Mac & Windows, when built with the 
>> > latest Qt5 on Intel.
>> >
>> > The code also builds OK with the latest Qt6, but running it on an M1 Mac 
>> > gives run-time errors. Void pointers to structs and objects don't cast 
>> > properly and stay null.  We haven't tried Qt6 on Windows yet but will do 
>> > that soon.
>> >
>> > Any ideas on how to fix it?  We've abandoned NeoAccess for our new app but 
>> > still need it to convert data from existing files.  Rewriting their code 
>> > is a nightmare.
>>
>> Casey,
>> Perhaps, checking the alignment of the void* pointers in question
>> could provide you with some clues.
>>
>> Kind regards,
>> Robert Iakobashvili
>> 
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-19 Thread Turtle Creek Software
Alignment is definitely possible.  There was a similar problem earlier in
execution, and that had pointers to 2-byte aligned structs.
We just rewrote the ugly void* code rather than try to diagnose it
further.  The debugger showed the correct address but failed to cast a
parameter.

Can the ARM compiler handle #pragma pack (2) ?

Thanks,
Casey McDermott
TurtleSoft.com

On Mon, Jun 19, 2023 at 2:50 AM coroberti  wrote:

> On Sat, Jun 17, 2023 at 8:12 PM Turtle Creek Software
>  wrote:
> >
> > Our app contains some old C-ish C++ code from an early 90's database
> called NeoAccess. It often uses function pointers with void pointers as
> parameters.  Their code works OK for Mac & Windows, when built with the
> latest Qt5 on Intel.
> >
> > The code also builds OK with the latest Qt6, but running it on an M1 Mac
> gives run-time errors. Void pointers to structs and objects don't cast
> properly and stay null.  We haven't tried Qt6 on Windows yet but will do
> that soon.
> >
> > Any ideas on how to fix it?  We've abandoned NeoAccess for our new app
> but still need it to convert data from existing files.  Rewriting their
> code is a nightmare.
>
> Casey,
> Perhaps, checking the alignment of the void* pointers in question
> could provide you with some clues.
>
> Kind regards,
> Robert Iakobashvili
> 
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-19 Thread coroberti
On Sat, Jun 17, 2023 at 8:12 PM Turtle Creek Software
 wrote:
>
> Our app contains some old C-ish C++ code from an early 90's database called 
> NeoAccess. It often uses function pointers with void pointers as parameters.  
> Their code works OK for Mac & Windows, when built with the latest Qt5 on 
> Intel.
>
> The code also builds OK with the latest Qt6, but running it on an M1 Mac 
> gives run-time errors. Void pointers to structs and objects don't cast 
> properly and stay null.  We haven't tried Qt6 on Windows yet but will do that 
> soon.
>
> Any ideas on how to fix it?  We've abandoned NeoAccess for our new app but 
> still need it to convert data from existing files.  Rewriting their code is a 
> nightmare.

Casey,
Perhaps, checking the alignment of the void* pointers in question
could provide you with some clues.

Kind regards,
Robert Iakobashvili

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Void pointers for Mac ARM

2023-06-18 Thread Thiago Macieira
On Saturday, 17 June 2023 10:09:42 PDT Turtle Creek Software wrote:
> The code also builds OK with the latest Qt6, but running it on an M1 Mac
> gives run-time errors. Void pointers to structs and objects don't cast
> properly and stay null.

Your diagnosis can't be correct.

The ABI on Arm Macs is very similar and reinterpret-casting between different 
pointer types, especially between function pointers and void*, is a simple 
bitwise copy.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering


smime.p7s
Description: S/MIME cryptographic signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest