[cfe-dev] __maybe_unused for conditional struct field?
Vincent Li via cfe-dev
cfe-dev at lists.llvm.org
Fri Nov 5 08:22:32 PDT 2021
Hi,
I could be not making sense here since I am newbie to compiler and
not even sure if this is a problem that compiler should care to
address
I ran into this
https://github.com/cilium/cilium/pull/17370#discussion_r731170618
where the suggestion to add conditional field like below,
struct remote_endpoint_info {
__u32 sec_label;
__u32 tunnel_endpoint;
#ifdef ENABLE_VTEP
mac_t vtep_mac;
#endif
__u8 key;
};
but it cause misalignment issue with golang struct below:
// RemoteEndpointInfo implements the bpf.MapValue interface. It contains the
// security identity of a remote endpoint.
// +k8s:deepcopy-gen=true
+k8s:deepcopy-gen:interfaces=github.com/cilium/cilium/pkg/bpf.MapValue
type RemoteEndpointInfo struct {
SecurityIdentity uint32 `align:"sec_label"`
TunnelEndpoint types.IPv4 `align:"tunnel_endpoint"`
VtepMAC mac.Uint64MAC `align:"vtep_mac"`
Key uint8 `align:"key"`
}
so out of my imagination without understanding things going on
underneath, I attempted to use __maybe_unused since I saw it being
used for stack variable,
struct remote_endpoint_info {
__u32 sec_label;
__u32 tunnel_endpoint;
mac_t vtep_mac __maybe_unused;
__u8 key;
};
the clang llvm did not complain error, but it has no effect on the
struct memory layout neither, so I wonder if __maybe_unused to struct
field is a thing, or if I am looking for wrong solution for the
problem, appreciate any input
Thanks
Vincent
More information about the cfe-dev
mailing list