Replace __packed with __attribute__((__packed__)) in uapi headers
Linux uapi headers use __packed as an abbreviation for
__attribute__((__packed__)). In the upstream kernel headers this
is defined in linux/compiler_attributes.h, but it is not defined
in the uapi headers. Bionic defines it in sys/cdefs.h, which will
almost always provide the needed definition, but there are uapi
headers that use __packed and do not include any system headers
that would include sys/cdefs.h. Musl's sys/cdefs.h does not
define __packed, which leads to linker errors when __packed is
treated as a variable name.
Replace __packed with __attribute__((__packed__)) when importing
uapi headers to break the dependency on sys/cdefs.h.
Test: m USE_HOST_MUSL=true on oriole-userdebug in internal master
Change-Id: I45f80f4e5aec868b80ce8eb9d757a3e08ae3e1a9
diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py
index abb8f82..d0fe157 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -94,6 +94,9 @@
"__kernel_old_timeval": "timeval",
# Do the same for __kernel_old_itimerval as for timeval.
"__kernel_old_itimerval": "itimerval",
+ # Replace __packed with __attribute__((__packed__)) to avoid depending
+ # on sys/cdefs.h
+ "__packed": "__attribute__((__packed__))",
}
diff --git a/libc/kernel/uapi/drm/i915_drm.h b/libc/kernel/uapi/drm/i915_drm.h
index 3188908..198b969 100644
--- a/libc/kernel/uapi/drm/i915_drm.h
+++ b/libc/kernel/uapi/drm/i915_drm.h
@@ -788,7 +788,7 @@
__u64 flags;
__u64 mbz64[3];
struct i915_engine_class_instance engines[];
-} __packed;
+} __attribute__((__packed__));
#define I915_DEFINE_CONTEXT_ENGINES_PARALLEL_SUBMIT(name__,N__) struct { struct i915_user_extension base; __u16 engine_index; __u16 width; __u16 num_siblings; __u16 mbz16; __u64 flags; __u64 mbz64[3]; struct i915_engine_class_instance engines[N__]; \
} __attribute__((packed)) name__
struct i915_context_param_engines {
diff --git a/libc/kernel/uapi/linux/android/binder.h b/libc/kernel/uapi/linux/android/binder.h
index e3b3289..52f4c6b 100644
--- a/libc/kernel/uapi/linux/android/binder.h
+++ b/libc/kernel/uapi/linux/android/binder.h
@@ -189,7 +189,7 @@
struct binder_handle_cookie {
__u32 handle;
binder_uintptr_t cookie;
-} __packed;
+} __attribute__((__packed__));
struct binder_pri_desc {
__s32 priority;
__u32 desc;
diff --git a/libc/kernel/uapi/linux/dns_resolver.h b/libc/kernel/uapi/linux/dns_resolver.h
index 21cb5c0..e7113d0 100644
--- a/libc/kernel/uapi/linux/dns_resolver.h
+++ b/libc/kernel/uapi/linux/dns_resolver.h
@@ -55,13 +55,13 @@
__u8 zero;
__u8 content;
__u8 version;
-} __packed;
+} __attribute__((__packed__));
struct dns_server_list_v1_header {
struct dns_payload_header hdr;
__u8 source;
__u8 status;
__u8 nr_servers;
-} __packed;
+} __attribute__((__packed__));
struct dns_server_list_v1_server {
__u16 name_len;
__u16 priority;
@@ -71,8 +71,8 @@
__u8 status;
__u8 protocol;
__u8 nr_addrs;
-} __packed;
+} __attribute__((__packed__));
struct dns_server_list_v1_address {
__u8 address_type;
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/linux/if_pppox.h b/libc/kernel/uapi/linux/if_pppox.h
index b6c076b..2acafdf 100644
--- a/libc/kernel/uapi/linux/if_pppox.h
+++ b/libc/kernel/uapi/linux/if_pppox.h
@@ -51,27 +51,27 @@
struct pppoe_addr pppoe;
struct pptp_addr pptp;
} sa_addr;
-} __packed;
+} __attribute__((__packed__));
struct sockaddr_pppol2tp {
__kernel_sa_family_t sa_family;
unsigned int sa_protocol;
struct pppol2tp_addr pppol2tp;
-} __packed;
+} __attribute__((__packed__));
struct sockaddr_pppol2tpin6 {
__kernel_sa_family_t sa_family;
unsigned int sa_protocol;
struct pppol2tpin6_addr pppol2tp;
-} __packed;
+} __attribute__((__packed__));
struct sockaddr_pppol2tpv3 {
__kernel_sa_family_t sa_family;
unsigned int sa_protocol;
struct pppol2tpv3_addr pppol2tp;
-} __packed;
+} __attribute__((__packed__));
struct sockaddr_pppol2tpv3in6 {
__kernel_sa_family_t sa_family;
unsigned int sa_protocol;
struct pppol2tpv3in6_addr pppol2tp;
-} __packed;
+} __attribute__((__packed__));
#define PPPOEIOCSFWD _IOW(0xB1, 0, size_t)
#define PPPOEIOCDFWD _IO(0xB1, 1)
#define PADI_CODE 0x09
@@ -108,6 +108,6 @@
__be16 sid;
__be16 length;
struct pppoe_tag tag[];
-} __packed;
+} __attribute__((__packed__));
#define PPPOE_SES_HLEN 8
#endif
diff --git a/libc/kernel/uapi/linux/ndctl.h b/libc/kernel/uapi/linux/ndctl.h
index f6b9f7f..7e0d560 100644
--- a/libc/kernel/uapi/linux/ndctl.h
+++ b/libc/kernel/uapi/linux/ndctl.h
@@ -22,33 +22,33 @@
struct nd_cmd_dimm_flags {
__u32 status;
__u32 flags;
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_get_config_size {
__u32 status;
__u32 config_size;
__u32 max_xfer;
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_get_config_data_hdr {
__u32 in_offset;
__u32 in_length;
__u32 status;
__u8 out_buf[];
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_set_config_hdr {
__u32 in_offset;
__u32 in_length;
__u8 in_buf[];
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_vendor_hdr {
__u32 opcode;
__u32 in_length;
__u8 in_buf[];
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_vendor_tail {
__u32 status;
__u32 out_length;
__u8 out_buf[];
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_ars_cap {
__u64 address;
__u64 length;
@@ -57,7 +57,7 @@
__u32 clear_err_unit;
__u16 flags;
__u16 reserved;
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_ars_start {
__u64 address;
__u64 length;
@@ -66,7 +66,7 @@
__u8 reserved[5];
__u32 status;
__u32 scrub_time;
-} __packed;
+} __attribute__((__packed__));
struct nd_cmd_ars_status {
__u32 status;
__u32 out_length;
@@ -82,15 +82,15 @@
__u32 reserved;
__u64 err_address;
__u64 length;
- } __packed records[];
-} __packed;
+ } __attribute__((__packed__)) records[];
+} __attribute__((__packed__));
struct nd_cmd_clear_error {
__u64 address;
__u64 length;
__u32 status;
__u8 reserved[4];
__u64 cleared;
-} __packed;
+} __attribute__((__packed__));
enum {
ND_CMD_IMPLEMENTED = 0,
ND_CMD_ARS_CAP = 1,
diff --git a/libc/kernel/uapi/linux/psp-sev.h b/libc/kernel/uapi/linux/psp-sev.h
index 6c4f73d..8c9ec80 100644
--- a/libc/kernel/uapi/linux/psp-sev.h
+++ b/libc/kernel/uapi/linux/psp-sev.h
@@ -66,37 +66,37 @@
__u32 flags;
__u8 build;
__u32 guest_count;
-} __packed;
+} __attribute__((__packed__));
#define SEV_STATUS_FLAGS_CONFIG_ES 0x0100
struct sev_user_data_pek_csr {
__u64 address;
__u32 length;
-} __packed;
+} __attribute__((__packed__));
struct sev_user_data_pek_cert_import {
__u64 pek_cert_address;
__u32 pek_cert_len;
__u64 oca_cert_address;
__u32 oca_cert_len;
-} __packed;
+} __attribute__((__packed__));
struct sev_user_data_pdh_cert_export {
__u64 pdh_cert_address;
__u32 pdh_cert_len;
__u64 cert_chain_address;
__u32 cert_chain_len;
-} __packed;
+} __attribute__((__packed__));
struct sev_user_data_get_id {
__u8 socket1[64];
__u8 socket2[64];
-} __packed;
+} __attribute__((__packed__));
struct sev_user_data_get_id2 {
__u64 address;
__u32 length;
-} __packed;
+} __attribute__((__packed__));
struct sev_issue_cmd {
__u32 cmd;
__u64 data;
__u32 error;
-} __packed;
+} __attribute__((__packed__));
#define SEV_IOC_TYPE 'S'
#define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
#endif
diff --git a/libc/kernel/uapi/linux/qrtr.h b/libc/kernel/uapi/linux/qrtr.h
index c0a4c72..ee56aca 100644
--- a/libc/kernel/uapi/linux/qrtr.h
+++ b/libc/kernel/uapi/linux/qrtr.h
@@ -54,5 +54,5 @@
__le32 port;
} client;
};
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/linux/target_core_user.h b/libc/kernel/uapi/linux/target_core_user.h
index daecb7d..83e155e 100644
--- a/libc/kernel/uapi/linux/target_core_user.h
+++ b/libc/kernel/uapi/linux/target_core_user.h
@@ -34,7 +34,7 @@
__u32 cmdr_size;
__u32 cmd_head;
__u32 cmd_tail __attribute__((__aligned__(ALIGN_SIZE)));
-} __packed;
+} __attribute__((__packed__));
enum tcmu_opcode {
TCMU_OP_PAD = 0,
TCMU_OP_CMD,
@@ -48,7 +48,7 @@
#define TCMU_UFLAG_READ_LEN 0x2
#define TCMU_UFLAG_KEEP_BUF 0x4
__u8 uflags;
-} __packed;
+} __attribute__((__packed__));
#define TCMU_OP_MASK 0x7
#define TCMU_SENSE_BUFFERSIZE 96
struct tcmu_cmd_entry {
@@ -71,7 +71,7 @@
char sense_buffer[TCMU_SENSE_BUFFERSIZE];
} rsp;
};
-} __packed;
+} __attribute__((__packed__));
struct tcmu_tmr_entry {
struct tcmu_cmd_entry_hdr hdr;
#define TCMU_TMR_UNKNOWN 0
@@ -90,7 +90,7 @@
__u64 __pad3;
__u64 __pad4;
__u16 cmd_ids[];
-} __packed;
+} __attribute__((__packed__));
#define TCMU_OP_ALIGN_SIZE sizeof(__u64)
enum tcmu_genl_cmd {
TCMU_CMD_UNSPEC,
diff --git a/libc/kernel/uapi/linux/userfaultfd.h b/libc/kernel/uapi/linux/userfaultfd.h
index 46d7472..0f18ecc 100644
--- a/libc/kernel/uapi/linux/userfaultfd.h
+++ b/libc/kernel/uapi/linux/userfaultfd.h
@@ -73,7 +73,7 @@
__u64 reserved3;
} reserved;
} arg;
-} __packed;
+} __attribute__((__packed__));
#define UFFD_EVENT_PAGEFAULT 0x12
#define UFFD_EVENT_FORK 0x13
#define UFFD_EVENT_REMAP 0x14
diff --git a/libc/kernel/uapi/linux/uvcvideo.h b/libc/kernel/uapi/linux/uvcvideo.h
index 719147a..46528a9 100644
--- a/libc/kernel/uapi/linux/uvcvideo.h
+++ b/libc/kernel/uapi/linux/uvcvideo.h
@@ -68,5 +68,5 @@
__u8 length;
__u8 flags;
__u8 buf[];
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/linux/vbox_vmmdev_types.h b/libc/kernel/uapi/linux/vbox_vmmdev_types.h
index 009f9a6..777a2bb 100644
--- a/libc/kernel/uapi/linux/vbox_vmmdev_types.h
+++ b/libc/kernel/uapi/linux/vbox_vmmdev_types.h
@@ -157,7 +157,7 @@
__u32 offset;
} page_list;
} u;
-} __packed;
+} __attribute__((__packed__));
struct vmmdev_hgcm_function_parameter64 {
enum vmmdev_hgcm_function_parameter_type type;
union {
@@ -169,13 +169,13 @@
__u64 phys_addr;
__u64 linear_addr;
} u;
- } __packed pointer;
+ } __attribute__((__packed__)) pointer;
struct {
__u32 size;
__u32 offset;
} page_list;
- } __packed u;
-} __packed;
+ } __attribute__((__packed__)) u;
+} __attribute__((__packed__));
#if __BITS_PER_LONG == 64
#define vmmdev_hgcm_function_parameter vmmdev_hgcm_function_parameter64
#else
diff --git a/libc/kernel/uapi/linux/vfio_ccw.h b/libc/kernel/uapi/linux/vfio_ccw.h
index a6defc5..7bf08f5 100644
--- a/libc/kernel/uapi/linux/vfio_ccw.h
+++ b/libc/kernel/uapi/linux/vfio_ccw.h
@@ -27,19 +27,19 @@
#define IRB_AREA_SIZE 96
__u8 irb_area[IRB_AREA_SIZE];
__u32 ret_code;
-} __packed;
+} __attribute__((__packed__));
#define VFIO_CCW_ASYNC_CMD_HSCH (1 << 0)
#define VFIO_CCW_ASYNC_CMD_CSCH (1 << 1)
struct ccw_cmd_region {
__u32 command;
__u32 ret_code;
-} __packed;
+} __attribute__((__packed__));
struct ccw_schib_region {
#define SCHIB_AREA_SIZE 52
__u8 schib_area[SCHIB_AREA_SIZE];
-} __packed;
+} __attribute__((__packed__));
struct ccw_crw_region {
__u32 crw;
__u32 pad;
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/linux/wmi.h b/libc/kernel/uapi/linux/wmi.h
index 26f54d9..7b72056 100644
--- a/libc/kernel/uapi/linux/wmi.h
+++ b/libc/kernel/uapi/linux/wmi.h
@@ -30,17 +30,17 @@
__u16 cmd_select;
volatile __u32 input[4];
volatile __u32 output[4];
-} __packed;
+} __attribute__((__packed__));
struct dell_wmi_extensions {
__u32 argattrib;
__u32 blength;
__u8 data[];
-} __packed;
+} __attribute__((__packed__));
struct dell_wmi_smbios_buffer {
__u64 length;
struct calling_interface_buffer std;
struct dell_wmi_extensions ext;
-} __packed;
+} __attribute__((__packed__));
#define CLASS_TOKEN_READ 0
#define CLASS_TOKEN_WRITE 1
#define SELECT_TOKEN_STD 0
diff --git a/libc/kernel/uapi/linux/zorro.h b/libc/kernel/uapi/linux/zorro.h
index f8e47a1..86320aa 100644
--- a/libc/kernel/uapi/linux/zorro.h
+++ b/libc/kernel/uapi/linux/zorro.h
@@ -42,7 +42,7 @@
__u8 ln_Type;
__s8 ln_Pri;
__be32 ln_Name;
-} __packed;
+} __attribute__((__packed__));
struct ExpansionRom {
__u8 er_Type;
__u8 er_Product;
@@ -55,7 +55,7 @@
__u8 er_Reserved0d;
__u8 er_Reserved0e;
__u8 er_Reserved0f;
-} __packed;
+} __attribute__((__packed__));
#define ERT_TYPEMASK 0xc0
#define ERT_ZORROII 0xc0
#define ERT_ZORROIII 0x80
@@ -73,6 +73,6 @@
__be32 cd_Driver;
__be32 cd_NextCD;
__be32 cd_Unused[4];
-} __packed;
+} __attribute__((__packed__));
#define ZORRO_NUM_AUTO 16
#endif
diff --git a/libc/kernel/uapi/mtd/ubi-user.h b/libc/kernel/uapi/mtd/ubi-user.h
index 866fbd2..a1143bc 100644
--- a/libc/kernel/uapi/mtd/ubi-user.h
+++ b/libc/kernel/uapi/mtd/ubi-user.h
@@ -71,11 +71,11 @@
__s16 name_len;
__s8 padding2[4];
char name[UBI_MAX_VOLUME_NAME + 1];
-} __packed;
+} __attribute__((__packed__));
struct ubi_rsvol_req {
__s64 bytes;
__s32 vol_id;
-} __packed;
+} __attribute__((__packed__));
struct ubi_rnvol_req {
__s32 count;
__s8 padding1[12];
@@ -85,24 +85,24 @@
__s8 padding2[2];
char name[UBI_MAX_VOLUME_NAME + 1];
} ents[UBI_MAX_RNVOL];
-} __packed;
+} __attribute__((__packed__));
struct ubi_leb_change_req {
__s32 lnum;
__s32 bytes;
__s8 dtype;
__s8 padding[7];
-} __packed;
+} __attribute__((__packed__));
struct ubi_map_req {
__s32 lnum;
__s8 dtype;
__s8 padding[3];
-} __packed;
+} __attribute__((__packed__));
struct ubi_set_vol_prop_req {
__u8 property;
__u8 padding[7];
__u64 value;
-} __packed;
+} __attribute__((__packed__));
struct ubi_blkcreate_req {
__s8 padding[128];
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/sound/asoc.h b/libc/kernel/uapi/sound/asoc.h
index eeb12b0..1940e5d 100644
--- a/libc/kernel/uapi/sound/asoc.h
+++ b/libc/kernel/uapi/sound/asoc.h
@@ -356,7 +356,7 @@
__le32 pcm_elems;
__le32 dai_link_elems;
struct snd_soc_tplg_private priv;
-} __packed;
+} __attribute__((__packed__));
struct snd_soc_tplg_stream_caps_v4 {
__le32 size;
char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
@@ -372,7 +372,7 @@
__le32 period_size_max;
__le32 buffer_size_min;
__le32 buffer_size_max;
-} __packed;
+} __attribute__((__packed__));
struct snd_soc_tplg_pcm_v4 {
__le32 size;
char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
@@ -385,11 +385,11 @@
struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX];
__le32 num_streams;
struct snd_soc_tplg_stream_caps_v4 caps[2];
-} __packed;
+} __attribute__((__packed__));
struct snd_soc_tplg_link_config_v4 {
__le32 size;
__le32 id;
struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX];
__le32 num_streams;
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/sound/asound.h b/libc/kernel/uapi/sound/asound.h
index 7f496d9..6e325e9 100644
--- a/libc/kernel/uapi/sound/asound.h
+++ b/libc/kernel/uapi/sound/asound.h
@@ -605,7 +605,7 @@
__u32 tv_nsec;
__u64 tv_sec;
__u8 data[SNDRV_RAWMIDI_FRAMING_DATA_LENGTH];
-} __packed;
+} __attribute__((__packed__));
struct snd_rawmidi_params {
int stream;
size_t buffer_size;
diff --git a/libc/kernel/uapi/sound/skl-tplg-interface.h b/libc/kernel/uapi/sound/skl-tplg-interface.h
index 387d168..6dd9655 100644
--- a/libc/kernel/uapi/sound/skl-tplg-interface.h
+++ b/libc/kernel/uapi/sound/skl-tplg-interface.h
@@ -111,7 +111,7 @@
__u32 param_id;
__u32 max;
char params[];
-} __packed;
+} __attribute__((__packed__));
enum skl_tkn_dir {
SKL_DIR_IN,
SKL_DIR_OUT
@@ -123,7 +123,7 @@
struct skl_dfw_v4_module_pin {
__u16 module_id;
__u16 instance_id;
-} __packed;
+} __attribute__((__packed__));
struct skl_dfw_v4_module_fmt {
__u32 channels;
__u32 freq;
@@ -133,21 +133,21 @@
__u32 interleaving_style;
__u32 sample_type;
__u32 ch_map;
-} __packed;
+} __attribute__((__packed__));
struct skl_dfw_v4_module_caps {
__u32 set_params : 2;
__u32 rsvd : 30;
__u32 param_id;
__u32 caps_size;
__u32 caps[HDA_SST_CFG_MAX];
-} __packed;
+} __attribute__((__packed__));
struct skl_dfw_v4_pipe {
__u8 pipe_id;
__u8 pipe_priority;
__u16 conn_type : 4;
__u16 rsvd : 4;
__u16 memory_pages : 8;
-} __packed;
+} __attribute__((__packed__));
struct skl_dfw_v4_module {
char uuid[SKL_UUID_STR_SZ];
__u16 module_id;
@@ -181,5 +181,5 @@
struct skl_dfw_v4_module_pin in_pin[MAX_IN_QUEUE];
struct skl_dfw_v4_module_pin out_pin[MAX_OUT_QUEUE];
struct skl_dfw_v4_module_caps caps;
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/sound/sof/fw.h b/libc/kernel/uapi/sound/sof/fw.h
index c36c2b9..97b7de3 100644
--- a/libc/kernel/uapi/sound/sof/fw.h
+++ b/libc/kernel/uapi/sound/sof/fw.h
@@ -46,7 +46,7 @@
enum snd_sof_fw_blk_type type;
__u32 size;
__u32 offset;
-} __packed;
+} __attribute__((__packed__));
enum snd_sof_fw_mod_type {
SOF_FW_BASE = 0,
SOF_FW_MODULE = 1,
@@ -55,11 +55,11 @@
enum snd_sof_fw_mod_type type;
__u32 size;
__u32 num_blocks;
-} __packed;
+} __attribute__((__packed__));
struct snd_sof_fw_header {
unsigned char sig[SND_SOF_FW_SIG_SIZE];
__u32 file_size;
__u32 num_modules;
__u32 abi;
-} __packed;
+} __attribute__((__packed__));
#endif
diff --git a/libc/kernel/uapi/sound/sof/header.h b/libc/kernel/uapi/sound/sof/header.h
index a1a13db..7514550 100644
--- a/libc/kernel/uapi/sound/sof/header.h
+++ b/libc/kernel/uapi/sound/sof/header.h
@@ -26,7 +26,7 @@
__u32 abi;
__u32 reserved[4];
__u32 data[];
-} __packed;
+} __attribute__((__packed__));
#define SOF_MANIFEST_DATA_TYPE_NHLT 1
struct sof_manifest_tlv {
__le32 type;