Page MenuHomeFreeBSD

Add sys/_align.h replacing machine/_align.h
AcceptedPublic

Authored by brooks on Thu, Nov 27, 3:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Dec 4, 7:22 AM
Unknown Object (File)
Wed, Dec 3, 7:33 AM
Unknown Object (File)
Wed, Dec 3, 6:22 AM
Unknown Object (File)
Mon, Dec 1, 5:20 AM
Unknown Object (File)
Sun, Nov 30, 9:29 PM
Unknown Object (File)
Sun, Nov 30, 8:56 PM
Unknown Object (File)
Sun, Nov 30, 8:06 PM
Unknown Object (File)
Fri, Nov 28, 9:50 PM

Details

Reviewers
kib
andrew
manu
markj
Group Reviewers
cheri
Summary

Define _ALIGNBYTES using sizeof(void *) (no functional change on any
existing architecture) which will allow it to work with CHERI were we
must align things up to capability alignment.

In _ALIGN, replace integer manipulation which does not preserve pointer
provenance with a type and provenance preserving builtin. This requires
modest changes in code which assumes _ALIGN returns an integer, but
those are relatively rare.

Effort: CHERI upstreaming
Sponsored by: Innovate UK

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 68952
Build 65835: arc lint + arc unit

Event Timeline

Would be good to indicate in the commit message how far back in gcc and clang __builtin_align_up is supported.

_ALIGNBYTES seems a bit underspecified and/or fraught. max_align_t is often higher than void * thanks to long double and/or int128. It would probably be more prudent to adapt to being explicit about what alignment each use case needs; many probably should be using max_align_t, or alignof(some struct being allocated). Then _ALIGNBYTES can remain for legacy use cases like cmsghdr where it's part of the ABI.

sys/sys/_align.h
21

We have __align_up as a shorter name for this

sys/sys/_align.h
18

The change seems to be true, from the summary description. IMO it is worth noting such detail.

  • Attempt to clarity _ALIGN's questionable interface
  • Use __align_up (just wraps the builtin which has is supported on all compilers that support typeof() by a fallback).
sys/sys/_align.h
25

BTW why is this thing declared obsolete? What should be used instead? __align_up directly?

sys/sys/_align.h
25

Presumably based on https://reviews.freebsd.org/D53947#1232673. It's insufficient alignment for some types, and it's overly-aligned for others. New code should use alignment based on the types of data it's trying to support. This just exists for compatibility with existing code that uses it, but should really have been more principled.

sys/sys/_align.h
25

i.e. instead of _ALIGNBYTES, use alignof(appropriate type), and instead of _ALIGN(p) use __align_up(p, alignof(appropriate type)).

sys/sys/_align.h
25

IMO this should be explained in the comment that declares the API obsolete.

Clarify why _ALIGN* are obsolete and what should be used instead.

This revision is now accepted and ready to land.Mon, Dec 1, 1:51 PM