Project

General

Profile

Actions

Bug #13457

open

smatch doesn't handle pragma-pack well

Added by Dan McDonald over 2 years ago. Updated over 2 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
tools - gate/build tools
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

Consider this structure from an upcoming i40e drop, and the existing compile-time assertion:

/* This macro is used to generate a compilation error if a structure
 * is not exactly the correct length. It gives a divide by zero error if the
 * structure is not of the correct size, otherwise it creates an enum that is
 * never used.
 */
#define I40E_CHECK_STRUCT_LEN(n, X) enum i40e_static_assert_enum_##X \
        { i40e_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }

/* This macro is used extensively to ensure that command structures are 16
 * bytes in length as they have to map to the raw array of that size.
 */
#define I40E_CHECK_CMD_LENGTH(X)        I40E_CHECK_STRUCT_LEN(16, X)

. . .

#pragma pack(1)
/* Run PHY Activity (0x0626) */
struct i40e_aqc_run_phy_activity {
        u8      cmd_flags;
        __le16  activity_id;
#define I40E_AQ_RUN_PHY_ACT_ID_USR_DFND                 0x10
        u8      reserved;
        union {
                struct {
                        __le32  dnl_opcode;
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT_DUR 0x801a
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT     0x801b
#define I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_DUR      0x1801b
                        __le32  data;
                        u8      reserved2[4];
                } cmd;
                struct {
                        __le32  cmd_status;
#define I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC               0x4
#define I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK               0xFFFF
                        __le32  data0;
                        __le32  data1;
                } resp;
        } params;
};
#pragma pack()

I40E_CHECK_CMD_LENGTH(i40e_aqc_run_phy_activity);

The current revision of smatch trips the compile check macro I40E_CHECK_CMD_LENGTH, but if I compile a C program with that structure, an mdb of it shows 16 bytes, so clearly smatch cannot honor the #pragma pack(1).

Actions #1

Updated by Dan McDonald over 2 years ago

  • Description updated (diff)
Actions #2

Updated by Dan McDonald over 2 years ago

We've worked around this by #ifdef sun around the I40E_CHECK_CMD_LENGTH() macro.

Actions

Also available in: Atom PDF