Opened 10 months ago

Last modified 9 months ago

#67790 new defect

ht: Fix arm64 compilation

Reported by: rdoeffinger (Reimar Döffinger) Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: arm64 haspatch Cc:
Port: ht

Description

This simple additional patch makes it compile, and as far as can tell work, on AppleSilicon devices: https://github.com/sebastianbiallas/ht/pull/31 Full diff:

diff --git a/httag.h b/httag.h
index 7f5da1c..5cbd500 100644
--- a/httag.h
+++ b/httag.h
@@ -71,7 +71,7 @@ struct ht_tag_flags {
 struct ht_tag_flags_s {
        char bitidx;
        const char *desc;
-} PACKED;
+};
 
 /* GROUP-TAG */
 #define HT_TAG_GROUP                           0x03

Change History (5)

comment:1 Changed 10 months ago by ryandesign (Ryan Carsten Schmidt)

Keywords: arm64 haspatch added
Summary: Fix arm64 compilationht: Fix arm64 compilation

comment:2 Changed 10 months ago by ryandesign (Ryan Carsten Schmidt)

I don't know the consequences of changing this struct from packed to not packed so let's wait to see what the developers say.

comment:3 Changed 10 months ago by jmroot (Joshua Root)

This will change the struct layout, which would break binary compatibility with anything using it, but fortunately it looks like this header is not intended to be used by anything but this program.

The packed declaration is presumably to avoid wasting memory with a "hole" in the struct due to alignment. It's traditional to declare struct members in order from largest to smallest alignment to avoid this problem while also avoiding unaligned accesses, which are usually less efficient even if the architecture allows them.

comment:4 Changed 10 months ago by rdoeffinger (Reimar Döffinger)

I agree that ideally we will get a response from upstream, just not sure how active they are.

So I'll provide a basic explanation what I think goes on here.

A lot of the structs in this file are meant to be serialized out into buffers.

HT_TAG_BUFOP adds functions like flush() that memcpy them and also special serialization functions in the .cc file. For that you'd want them packed, because both you'd not want random data from the padding to leak out and also for the size and layout to not depend on architecture/OS/compiler.

However in case of ht_tag_flags_s I suspect that PACKED was added by pure accident.

Why? First of all, PACKED was added in 5c0c87f2 along with all other structs in the file, so likely it was not closely reviewed. Second of all, this struct contains no HT_TAG_BUFOP, and it is the only one containing a pointer type. And it's not really possible to sensibly serialize a pointer to a buffer (without some special logic, which does not exist here).

I think, it is rather the opposite, the ht_tag_flags_s are a mapping between the values being serialized out and the strings they stand for, so they are explicitly meant to live only in the binary, not the buffers that are created here.

Thus I do think the change makes sense, however I agree it is sensible to wait a while and see if we can get an upstream response. I guess the only counter-point is, for AppleSilicon devices it currently does not compile at all, so applying it only for that case does not really make anything worse even if I'm wrong...

comment:5 Changed 9 months ago by rdoeffinger (Reimar Döffinger)

It's been a month, could you consider this change, independent from if and when upstream might get around to look into it?

Note: See TracTickets for help on using tickets.