Profiling 100s of structs to be 4 byte aligned.

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have 100s of structs in my project in AtmelStudio 7.

At times I forget to make sure the structs are 4 byte aligned. As this is a must for ARM controllers and also for UC3 series (good practice).

Is there any profiling tools out there that can list all the structs I have used in the project and show their sizes?

 

Regards,

Shahriar

 

Last Edited: Thu. Aug 27, 2020 - 08:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Normally the compiler will do this automatically, by adding padding (that you might not want.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I am sure it does, appropriately or otherwise. And there is then the CPU hang....and watchdog reboots. This is all known cases.

So I am trying to see if there is a way to quickly profile my code to see which structs or nested structs are NOT a multiple of 4 bytes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unless you do something funny (like use the "packed" attribute on a struct), all structs and struct members will be aligned appropriately for the target architecture. It would be a real headache if they weren't! (And GCC is smart enough to know how to properly access unaligned members in a "packed" struct.)

 

What makes you believe that any of your structs are misaligned, or that misaligned structs are the cause of CPU hangs?

 

In my mind, this is a red herring unless you can show that even one of your structs is actually misaligned.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this is a must for ARM controllers

 Not true, BTW.  Some ARMs support unaligned memory accesses.  (looks like ARM-v7m (CM3, CM4) should support unaligned accesses, and ARM-v6m (M0, m0+) doesn't.  Might be "implementation dependent."

( "some memory regions might not support unaligned accesses.")

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds like an opportunity to make use of compile-time static_assert()s in conjunction with sizeof() and offsetof().

 

Steve

Maverick Embedded Technologies Ltd. Home of Maven and wAVR.

Maven: WiFi ARM Cortex-M Debugger/Programmer

wAVR: WiFi AVR ISP/PDI/uPDI Programmer

https://www.maverick-embedded.co...