develooper Front page | perl.perl6.internals | Postings from August 2002

struct padding warnings

Thread Next
Nicholas Clark
August 24, 2002 06:58
struct padding warnings
Message ID:
The idea is that we turn on all the bondage and discipline warnings, and then
still compile squeaky clean despite them, isn't it?

If so, we have a problem to solve:

string.h has this:

/* Tail added to end of string buffers; used for COW GC */
struct Buffer_Tail {
    unsigned char flags;

On ARM, in every file, I see this:

In file included from include/parrot/register.h:16,
                 from include/parrot/interpreter.h:42,
                 from include/parrot/parrot.h:160,
                 from jit_cpu.c:11:
include/parrot/string.h:59: warning: padding struct size to alignment boundary

because that structure is getting padded to 4 bytes, and gcc's -Wpadded is
telling us.

I don't like having a warning enabled that we're ignoring. I can see several

1: Turn off -Wpadded  (bad IMO, as there are other warnings it is telling
   us about that we can fix)
2: Re-write that struct as something 32 bit, such as an int.
   (probably also bad, because that wastes space on most other platforms)
3: Determine minimum structure size at time, and then have an
   #ifdef in structures such as that one that have odd sizes to insert some
   padding chars
   (Clunky, but should work, and will give optimum size on all platforms
   without the warning. And I'll have a go at this if no-one objects or has
   better ideas)

With -Wpadded turned off, there would be no warning about evil evil evil [:-)]
CISC-over-friendly structures such as:

typedef struct Parrot_jit_optimizer_section {
    opcode_t                            *begin;
    opcode_t                            *end;
    Parrot_jit_register_count_t          int_reg_count[NUM_REGISTERS];
    Parrot_jit_register_usage_t          int_reg_usage[NUM_REGISTERS];
    Parrot_jit_register_dir_t            int_reg_dir[NUM_REGISTERS];
    unsigned char                        int_registers_used;
    Parrot_jit_register_count_t          float_reg_count[NUM_REGISTERS];
    Parrot_jit_register_usage_t          float_reg_usage[NUM_REGISTERS];
    Parrot_jit_register_dir_t            float_reg_dir[NUM_REGISTERS];
    unsigned char                        float_registers_used;
    Parrot_jit_arena_t                  *arena;
    unsigned int                         maps;
    unsigned int                         jit_op_count;
    unsigned int                         op_count;
    ptrdiff_t                            load_size;
    char                                 type;
    Parrot_jit_optimizer_section_ptr     branch_target;
    Parrot_jit_optimizer_section_ptr     prev;
    Parrot_jit_optimizer_section_ptr     next;
} Parrot_jit_optimizer_section_t;

All those char elements are giving alignment padding warnings.
But as is, even moving all 3 of them together (and to the end) would still
give a warning on ARM, because the resultant structure would need one more
byte's padding to get to a multiple of 4 bytes.

Nicholas Clark
Even better than the real thing:

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About