[arm_compiler_v4/v5] define rt_packed as __packed#10553
[arm_compiler_v4/v5] define rt_packed as __packed#10553Rbb666 merged 2 commits intoRT-Thread:masterfrom
Conversation
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-08-06 10:27 CST)
📝 Review Instructions
|
|
The __packed qualifier sets the alignment of any valid type to 1. #pragma pack(2) // 强制后续所有结构体按 2 字节对齐
typedef struct {
uint8_t a; // 偏移 0
uint16_t b; // 偏移 2 (自动跳过 1 字节)
uint32_t c; // 偏移 4
} MyStruct; // 总大小 = 8 字节
#pragma pack() // 恢复默认对齐 |
抱歉 我的理解可能有误 似乎这个宏只是为了1字节对齐 如果是这样的话 当前这个是可以的 #define rt_packed(declare) __packed declare不过建议一个PR只改一个 我看你还修改了其他文件 |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes memory alignment issues in ARM Compiler v4/v5 by properly defining the rt_packed macro to use __packed instead of an empty definition. The change addresses memory corruption problems that occur when using MDK5 compiler due to improper byte alignment in data structures.
- Updates
rt_packedmacro definition for ARM Compiler versions below 6.01.05 to use__packed - Fixes existing struct definitions to use the corrected packed attribute syntax
- Resolves memory corruption issue in the
find_valid_gptfunction caused by incorrect sizeof calculations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| include/rtcompiler.h | Updates rt_packed macro to use __packed for ARM Compiler v4/v5 |
| components/drivers/include/drivers/nvme.h | Converts struct definition to use rt_packed macro correctly |
| components/drivers/block/partitions/efi.h | Adds packed attribute to guid_t typedef struct |
Comments suppressed due to low confidence (1)
components/drivers/block/partitions/efi.h:33
- The syntax 'typedef struct rt_packed' is incorrect. Based on the rt_packed macro definition change, this should be 'rt_packed(typedef struct' with a corresponding closing parenthesis, or use 'typedef rt_packed(struct' to match the pattern used in nvme.h.
typedef struct rt_packed
|
LGTM |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
使用MDK5编译器编译工程后,在运行find_valid_gpt函数时, 因sizeof (legacy_mbr)得出的长度未按1字节对齐而出现内存覆盖问题
你的解决方案是什么 (what is your solution)
1、当 __ARMCC_VERSION < 6010050 时定义 rt_packed 为 __packed
2、参考文档:
1)ARM Compiler toolchain Using the Compiler Version 5.01
https://developer.arm.com/documentation/dui0472/g/compiler-coding-practices/the---packed-qualifier-and-unaligned-data-access-in-c-and-c---code?lang=en
2)ARM Compiler toolchain Using the Compiler Version 4.1
https://developer.arm.com/documentation/dui0472/c/compiler-coding-practices/the---packed-qualifier-and-unaligned-data-access-in-c-and-c---code?lang=en
3)ARM Software Development Toolkit Reference Guide Version 2.50
https://developer.arm.com/documentation/dui0041/c/ARM-Compiler-Reference/Compiler-specific-features/Type-qualifiers?lang=en
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up