carduinoavrarduino-unoavr-gcc

Casting a constant to a pointer increases .data size by 1000 bytes


I'm at a total loss with this one, I don't even know what to include in my question.

When I cast a constant to a pointer my (.data + .bss + .noinit) section grows by 1K, exceeding the ATmega328P's capacity.

PK16_TABLE_T* pk16_find_table_by_index(PK16_T* p_pkg, SIZE_T index)
{
    SIZE_T offset;
    PK16_TABLE_T* p_table;

    p_table = (PK16_TABLE_T*) 0;

    return p_table;
}

If I cast a pointer then the data size stays the same, not growing by 1K:

PK16_TABLE_T* pk16_find_table_by_index(PK16_T* p_pkg, SIZE_T index)
{
    SIZE_T offset;
    PK16_TABLE_T* p_table;

    p_table = (PK16_TABLE_T*) &offset;

    return p_table;
}

Where do I even start debugging this? What else do you need to see to be able to understand what might be happening?

/** A single entry in a PK16 package. */
typedef struct {
    /** Null-terminated string representing the path of this entry. */
    CHAR_T path[PK16_MAX_PATH_LEN];
    /** Index into the package data buffer of the start of this entry's data. */
    U16_T head;
    /** Length in bytes of this entry's data in the data buffer. */
    U16_T len;
    /** CRC32 of this entry's path + data. */
    U32_T crc;
} PK16_TABLE_T;

Solution

  • Someone in the comments helped me solve this, but they deleted their comment for some reason.

    I used readelf to analyze what symbol got added.

    It's the CRC32 polynomial table! I don't know why the constant cast decides whether that symbol gets included, but that's the answer.