Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packed pointer warning in LL Controller #20724

Closed
joerchan opened this issue Nov 15, 2019 · 9 comments
Closed

Packed pointer warning in LL Controller #20724

joerchan opened this issue Nov 15, 2019 · 9 comments
Assignees
Labels
area: Bluetooth bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@joerchan
Copy link
Contributor

Describe the bug
GCC 9 throws new warnings for possible unaligned pointer issues. On some architectures this is not supported, or can be configured to not be supported. On ARM this would throw a Hard Fault Exception.

To Reproduce
Steps to reproduce the behavior:
Build BT Controller with GCC v9

Impact
This could end in HardFault or other forms of crash.

Screenshots or console output

      [129/199] Building C object 
[142/199] Building C object zephyr/subsys/bluetooth/contr...MakeFiles/subsys__bluetooth__controller.dir/hci/hci.c.obj
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c: In function 'le_conn_complete':
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c:2776:9: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct node_rx_cc' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 2776 |  struct node_rx_cc *node_rx = (void *)pdu_data;
      |         ^~~~~~~~~~
In file included from /home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c:29:
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/./ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c:32:
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/./ll_sw/ull_conn_types.h:219:8: note: defined here
  219 | struct node_rx_cc {
      |        ^~~~~~~~~~
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c: In function 'le_conn_update_complete':
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c:2906:2: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct node_rx_cu' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 2906 |  cu = (void *)pdu_data;
      |  ^~
In file included from /home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c:29:
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/./ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev/zephyr/subsys/bluetooth/controller/hci/hci.c:32:
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/./ll_sw/ull_conn_types.h:235:8: note: defined here
  235 | struct node_rx_cu {
      |        ^~~~~~~~~~
[177/199] Building C object zephyr/subsys/bluetooth/contr...eFiles/subsys__bluetooth__controller.dir/ll_sw/ctrl.c.obj
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c: In function 'isr_rx_conn_pkt_ctrl_rej_conn_upd':
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:2175:2: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct radio_le_conn_update_cmplt' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 2175 |  cp = (void *)pdu_data_rx;
      |  ^~
In file included from /home/thomsten/dev/zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:42:
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev/zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:44:
/home/thomsten/dev/zephyr/subsys/bluetooth/controller/ll_sw/ctrl.h:144:8: note: defined here
  144 | struct radio_le_conn_update_cmplt {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~

Environment (please complete the following information):

  • OS: Linux
  • Toolchain GCC v9
  • Commit: 2.0.0 (or current master).
@joerchan joerchan added bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug labels Nov 15, 2019
@dleach02
Copy link
Member

dleach02 commented Nov 15, 2019

This one does seem to be problematic:

warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct radio_le_conn_update_cmplt' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
2175 | cp = (void *)pdu_data_rx;

Generally, Arm would throw an exception when trying to do unaligned access but in the case of a packed structure with pointers and such the compiler normally knows this and will use "relaxed" rules when generating code around these. The relaxed rules result in unaligned accesses being structured with multiple byte or word accesses (what ever is allowed). But if you are assigning a pointer of different types where one structure is packed and the other is not then the compiler won't know to use the relaxed rules and the differing alignments would cause additional problems...

@cvinayak
Copy link
Contributor

I have analyzed the implementation, the packed struct pdu_data is used as place holder of pointer to the message passed from controller's ISR contect to HCI thread context. The access to data by both the producing and consuming implementation is by use of unpacked structures. The current upstream implementation does not lead to any unaligned access in the unpacked structures.

That said, I am not getting compile time warnings in my dev environ:

  • Archlinux distribution with gcc version 9.2.0 (Arch Repository)
  • export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
  • export GNUARMEMB_TOOLCHAIN_PATH=/usr

Is there something I need to do/add to build script to enable the reported warnings?

@thomasstenersen
Copy link
Collaborator

@cvinayak, here's the full output against vanilla Zephyr master branch (6ba1fce).

Compiler is

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (Fedora 9.2.0-1.fc30) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Building zephyr/samples/bluetooth/central_hr

-- west build: build configuration:
       source directory: /home/thomsten/dev2/zephyr/samples/bluetooth/central_hr
       build directory: /home/thomsten/dev2/zephyr/samples/bluetooth/central_hr/build (created)
       BOARD: nrf52_pca10040 (origin: command line)
-- west build: generating a build system
Zephyr version: 2.1.0
-- Found PythonInterp: /home/thomsten/.virtualenv/default/bin/python (found suitable version "3.7.3", minimum required is "3.4") 
-- Selected BOARD nrf52_pca10040
-- Found west: /home/thomsten/.virtualenv/default/bin/west (found suitable version "0.6.3", minimum required is "0.6.0")
-- Loading /home/thomsten/dev2/zephyr/boards/arm/nrf52_pca10040/nrf52_pca10040.dts as base
Devicetree configuration written to /home/thomsten/dev2/zephyr/samples/bluetooth/central_hr/build/zephyr/include/generated/generated_dts_board.conf
Parsing Kconfig tree in /home/thomsten/dev2/zephyr/Kconfig
Loaded configuration '/home/thomsten/dev2/zephyr/boards/arm/nrf52_pca10040/nrf52_pca10040_defconfig'
Merged configuration '/home/thomsten/dev2/zephyr/samples/bluetooth/central_hr/prj.conf'
Configuration saved to '/home/thomsten/dev2/zephyr/samples/bluetooth/central_hr/build/zephyr/.config'
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is unknown
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
-- Cache files will be written to: /home/thomsten/.cache/zephyr
-- Configuring done
-- Generating done
-- Build files have been written to: /home/thomsten/dev2/zephyr/samples/bluetooth/central_hr/build
-- west build: building application
[1/182] Preparing syscall dependency handling

[2/182] Generating include/generated/syscall_macros.h
[3/182] Generating misc/generated/syscalls_subdirs.trigger
[4/182] Generating include/generated/driver-validation.h
[5/182] Generating include/generated/kobj-types-enum.h, include/generated/otype-to-str.h
[6/182] Generating misc/generated/syscalls.json
[7/182] Generating include/generated/syscall_dispatch.c, include/generated/syscall_list.h
[8/182] Building C object zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj
[9/182] Generating include/generated/offsets.h
[10/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc8_sw.c.obj
[11/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc32_sw.c.obj
[12/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc16_sw.c.obj
[13/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/crc7_sw.c.obj
[14/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/dec.c.obj
[15/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/hex.c.obj
[16/182] Building C object CMakeFiles/app.dir/src/main.c.obj
[17/182] Linking C static library app/libapp.a
[18/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/sem.c.obj
[19/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/fdtable.c.obj
[20/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/timeutil.c.obj
[21/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/thread_entry.c.obj
[22/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/rb.c.obj
[23/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/mempool.c.obj
[24/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/work_q.c.obj
[25/182] Building C object zephyr/CMakeFiles/zephyr.dir/ext/lib/crypto/tinycrypt/source/utils.c.obj
[26/182] Building C object zephyr/CMakeFiles/zephyr.dir/misc/generated/configs.c.obj
[27/182] Building C object zephyr/CMakeFiles/zephyr.dir/soc/arm/nordic_nrf/validate_base_addresses.c.obj
[28/182] Building C object zephyr/CMakeFiles/zephyr.dir/ext/lib/crypto/tinycrypt/source/ecc_dh.c.obj
[29/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/printk.c.obj
[30/182] Building C object zephyr/CMakeFiles/zephyr.dir/ext/lib/crypto/tinycrypt/source/aes_decrypt.c.obj
[31/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_list.c.obj
[32/182] Building C object zephyr/CMakeFiles/zephyr.dir/ext/lib/crypto/tinycrypt/source/cmac_mode.c.obj
[33/182] Building C object zephyr/CMakeFiles/zephyr.dir/ext/lib/crypto/tinycrypt/source/aes_encrypt.c.obj
[34/182] Building C object zephyr/CMakeFiles/zephyr.dir/ext/lib/crypto/tinycrypt/source/ecc.c.obj
[35/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_backend_uart.c.obj
[36/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/net/lib/utils/addr_utils.c.obj
[37/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_msg.c.obj
[38/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_output.c.obj
[39/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/power/policy/policy_residency.c.obj
[40/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/power/power.c.obj
[41/182] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_core.c.obj
[42/182] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/console/uart_console.c.obj
[43/182] Generating linker.cmd
[44/182] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/timer/sys_clock_init.c.obj
[45/182] Building C object zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj
[46/182] Building C object zephyr/arch/common/CMakeFiles/arch__common.dir/isr_tables.c.obj
[47/182] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/exc_exit.S.obj
[48/182] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/clock_control/nrf_power_clock.c.obj
[49/182] Building C object zephyr/arch/common/CMakeFiles/arch__common.dir/sw_isr_common.c.obj
[50/182] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/swap_helper.S.obj
[51/182] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/swap.c.obj
[52/182] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/timer/nrf_rtc_timer.c.obj
[53/182] Linking C static library zephyr/arch/common/libarch__common.a
[54/182] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/cpu_idle.S.obj
[55/182] Linking C static library zephyr/libzephyr.a
[56/182] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/irq_manage.c.obj
[57/182] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/fault_s.S.obj
[58/182] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/nmi_on_reset.S.obj
[59/182] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/nmi.c.obj
[60/182] Building ASM object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/isr_wrapper.S.obj
[61/182] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/fatal.c.obj
[62/182] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/thread.c.obj
[63/182] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/vector_table.S.obj
[64/182] Building ASM object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/reset.S.obj
[65/182] Building C object zephyr/arch/arch/arm/core/CMakeFiles/arch__arm__core.dir/prep_c.c.obj
[66/182] Linking C static library zephyr/arch/arch/arm/core/libarch__arm__core.a
[67/182] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/scb.c.obj
[68/182] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/irq_init.c.obj
[69/182] Building C object zephyr/arch/arch/arm/core/cortex_m/mpu/CMakeFiles/arch__arm__core__cortex_m__mpu.dir/arm_core_mpu.c.obj
[70/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/atoi.c.obj
[71/182] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/thread_abort.c.obj
[72/182] Building C object zephyr/arch/arch/arm/core/cortex_m/CMakeFiles/arch__arm__core__cortex_m.dir/fault.c.obj
[73/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtoul.c.obj
[74/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtol.c.obj
[75/182] Linking C static library zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a
[76/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/malloc.c.obj
[77/182] Building C object zephyr/arch/arch/arm/core/cortex_m/mpu/CMakeFiles/arch__arm__core__cortex_m__mpu.dir/arm_mpu.c.obj
[78/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/bsearch.c.obj
[79/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strncasecmp.c.obj
[80/182] Linking C static library zephyr/arch/arch/arm/core/cortex_m/mpu/libarch__arm__core__cortex_m__mpu.a
[81/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strstr.c.obj
[82/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/exit.c.obj
[83/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strspn.c.obj
[84/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/stdout_console.c.obj
[85/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/fprintf.c.obj
[86/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/sprintf.c.obj
[87/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/time/gmtime.c.obj
[88/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/string.c.obj
[89/182] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/soc.c.obj
[90/182] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/prf.c.obj
[91/182] Building C object zephyr/lib/posix/CMakeFiles/lib__posix.dir/pthread_common.c.obj
[92/182] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/power.c.obj
[93/182] Linking C static library zephyr/lib/libc/minimal/liblib__libc__minimal.a
[94/182] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/mpu_regions.c.obj
[95/182] Linking C static library zephyr/lib/posix/liblib__posix.a
[96/182] Linking C static library zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a
[97/182] Building C object zephyr/subsys/bluetooth/common/CMakeFiles/subsys__bluetooth__common.dir/dummy.c.obj
[98/182] Building C object zephyr/subsys/bluetooth/common/CMakeFiles/subsys__bluetooth__common.dir/rpa.c.obj
[99/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/uuid.c.obj
[100/182] Building C object zephyr/subsys/bluetooth/common/CMakeFiles/subsys__bluetooth__common.dir/log.c.obj
[101/182] Linking C static library zephyr/subsys/bluetooth/common/libsubsys__bluetooth__common.a
[102/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/hci_ecc.c.obj
[103/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/l2cap.c.obj
[104/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/conn.c.obj
[105/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/att.c.obj
[106/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/mem.c.obj
[107/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/memq.c.obj
[108/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/keys.c.obj
[109/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/util.c.obj
[110/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/mayfly.c.obj
[111/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/gatt.c.obj
/home/thomsten/dev2/zephyr/subsys/bluetooth/host/gatt.c: In function 'sc_save':
/home/thomsten/dev2/zephyr/subsys/bluetooth/host/gatt.c:344:26: warning: taking address of packed member of 'struct sc_data' may result in an unaligned pointer value [-Waddress-of-packed-member]
  344 |  modified = update_range(&cfg->data.start, &cfg->data.end, start, end);
      |                          ^~~~~~~~~~~~~~~~
/home/thomsten/dev2/zephyr/subsys/bluetooth/host/gatt.c:344:44: warning: taking address of packed member of 'struct sc_data' may result in an unaligned pointer value [-Waddress-of-packed-member]
  344 |  modified = update_range(&cfg->data.start, &cfg->data.end, start, end);
      |                                            ^~~~~~~~~~~~~~
[112/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ll_addr.c.obj
[113/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ll_tx_pwr.c.obj
[114/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ticker/ticker.c.obj
[115/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/hci/hci_driver.c.obj
[116/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/crypto/crypto.c.obj
[117/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/lll_chan.c.obj
[118/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/smp.c.obj
[119/182] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/hci_core.c.obj
[120/182] Linking C static library zephyr/subsys/bluetooth/host/libsubsys__bluetooth__host.a
[121/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ull.c.obj
[122/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/hci/hci.c.obj
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c: In function 'le_conn_complete':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c:2776:9: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct node_rx_cc' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 2776 |  struct node_rx_cc *node_rx = (void *)pdu_data;
      |         ^~~~~~~~~~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c:29:
../../../../subsys/bluetooth/controller/./ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c:32:
../../../../subsys/bluetooth/controller/./ll_sw/ull_conn_types.h:275:8: note: defined here
  275 | struct node_rx_cc {
      |        ^~~~~~~~~~
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c: In function 'le_conn_update_complete':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c:2906:2: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct node_rx_cu' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 2906 |  cu = (void *)pdu_data;
      |  ^~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c:29:
../../../../subsys/bluetooth/controller/./ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/hci/hci.c:32:
../../../../subsys/bluetooth/controller/./ll_sw/ull_conn_types.h:291:8: note: defined here
  291 | struct node_rx_cu {
      |        ^~~~~~~~~~
[123/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/lll/lll.c.obj
[124/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ull_scan.c.obj
[125/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/lll/lll_clock.c.obj
[126/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/lll/lll_scan.c.obj
[127/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/lll/lll_conn.c.obj
[128/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ull_sched.c.obj
[129/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/hal/nrf5/cntr.c.obj
[130/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/lll/lll_master.c.obj
[131/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ull_master.c.obj
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_master.c: In function 'ull_master_setup':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_master.c:449:2: warning: converting a packed 'struct pdu_adv' pointer (alignment 1) to a 'struct node_rx_cc' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
  449 |  cc = (void *)pdu_tx;
      |  ^~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_master.c:19:
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/pdu.h:249:8: note: defined here
  249 | struct pdu_adv {
      |        ^~~~~~~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_master.c:35:
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn_types.h:275:8: note: defined here
  275 | struct node_rx_cc {
      |        ^~~~~~~~~~
[132/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/hal/nrf5/ecb.c.obj
[133/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/hal/nrf5/radio/radio.c.obj
[134/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/hal/nrf5/mayfly.c.obj
[135/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/nordic/hal/nrf5/ticker.c.obj
[136/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ull_filter.c.obj
[137/182] Building C object zephyr/subsys/random/CMakeFiles/subsys__random.dir/rand32_entropy_device.c.obj
[138/182] Linking C static library zephyr/subsys/random/libsubsys__random.a
[139/182] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uart.c.obj
[140/182] Linking C static library zephyr/drivers/serial/libdrivers__serial.a
[141/182] Building C object zephyr/subsys/net/CMakeFiles/subsys__net.dir/buf.c.obj
[142/182] Building C object zephyr/drivers/entropy/CMakeFiles/drivers__entropy.dir/entropy_nrf5.c.obj
[143/182] Linking C static library zephyr/subsys/net/libsubsys__net.a
[144/182] Building C object zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_nrfx.c.obj
[145/182] Linking C static library zephyr/drivers/entropy/libdrivers__entropy.a
[146/182] Building C object zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/ll_sw/ull_conn.c.obj
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c: In function 'event_conn_upd_init':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:2081:40: warning: taking address of packed member of 'struct pdu_data_llctrl_conn_update_ind' may result in an unaligned pointer value [-Waddress-of-packed-member]
 2081 |   conn->llcp.conn_upd.pdu_win_offset = (u16_t *)
      |                                        ^~~~~~~~~
 2082 |    &pdu_ctrl_tx->llctrl.conn_update_ind.win_offset;
      |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c: In function 'event_conn_param_req':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:2905:43: warning: taking address of packed member of 'struct pdu_data_llctrl_conn_param_req' may result in an unaligned pointer value [-Waddress-of-packed-member]
 2905 |   conn->llcp_conn_param.pdu_win_offset0 = (u16_t *)&p->offset0;
      |                                           ^~~~~~~~~~~~~~~~~~~~
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c: In function 'reject_ind_conn_upd_recv':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:4223:2: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct node_rx_cu' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 4223 |  cu = (void *)pdu_rx;
      |  ^~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:26:
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:30:
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn_types.h:291:8: note: defined here
  291 | struct node_rx_cu {
      |        ^~~~~~~~~~
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c: In function 'ctrl_rx':
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:5829:4: warning: converting a packed 'struct pdu_data' pointer (alignment 1) to a 'struct node_rx_cu' pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member]
 5829 |    cu = (void *)pdu_rx;
      |    ^~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:26:
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/pdu.h:511:8: note: defined here
  511 | struct pdu_data {
      |        ^~~~~~~~
In file included from /home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn.c:30:
/home/thomsten/dev2/zephyr/subsys/bluetooth/controller/ll_sw/ull_conn_types.h:291:8: note: defined here
  291 | struct node_rx_cu {
      |        ^~~~~~~~~~
[147/182] Building C object modules/nordic/CMakeFiles/..__modules__hal__nordic.dir/nrfx/mdk/system_nrf52.c.obj
[148/182] Linking C static library zephyr/drivers/gpio/libdrivers__gpio.a
[149/182] Linking C static library zephyr/subsys/bluetooth/controller/libsubsys__bluetooth__controller.a
[150/182] Building C object modules/nordic/CMakeFiles/..__modules__hal__nordic.dir/nrfx_glue.c.obj
[151/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/device.c.obj
[152/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/errno.c.obj
[153/182] Linking C static library modules/nordic/lib..__modules__hal__nordic.a
[154/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/idle.c.obj
[155/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/fatal.c.obj
[156/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mem_slab.c.obj
[157/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/init.c.obj
[158/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mempool.c.obj
[159/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mailbox.c.obj
[160/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/msg_q.c.obj
[161/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/mutex.c.obj
[162/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/sem.c.obj
[163/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/pipes.c.obj
[164/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/queue.c.obj
[165/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/stack.c.obj
[166/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/system_work_q.c.obj
[167/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/version.c.obj
[168/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/thread_abort.c.obj
[169/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/sched.c.obj
[170/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/work_q.c.obj
[171/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/smp.c.obj
[172/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/thread.c.obj
[173/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/timer.c.obj
[174/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/timeout.c.obj
[175/182] Building C object zephyr/kernel/CMakeFiles/kernel.dir/poll.c.obj
[176/182] Linking C static library zephyr/kernel/libkernel.a
[177/182] Linking C executable zephyr/zephyr_prebuilt.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      127991 B       512 KB     24.41%
            SRAM:       21020 B        64 KB     32.07%
        IDT_LIST:         120 B         2 KB      5.86%
[178/182] Generating linker_pass_final.cmd
[179/182] Generating isr_tables.c
[180/182] Building C object zephyr/CMakeFiles/zephyr_final.dir/misc/empty_file.c.obj
[181/182] Building C object zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj
[182/182] Linking C executable zephyr/zephyr.elf

@joerchan
Copy link
Contributor Author

I have analyzed the implementation, the packed struct pdu_data is used as place holder of pointer to the message passed from controller's ISR contect to HCI thread context. The access to data by both the producing and consuming implementation is by use of unpacked structures. The current upstream implementation does not lead to any unaligned access in the unpacked structures.

That said, I am not getting compile time warnings in my dev environ:

  • Archlinux distribution with gcc version 9.2.0 (Arch Repository)
  • export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
  • export GNUARMEMB_TOOLCHAIN_PATH=/usr

Is there something I need to do/add to build script to enable the reported warnings?

@cvinayak
Zephyr is not using your distributed GCC, it is using the one in zephyr-sdk. Thomas is using the GNUARMEMB toolchain option.

@cvinayak
Copy link
Contributor

cvinayak commented Nov 18, 2019

Build BT Controller with GCC v9

@thomasstenersen could you give me the commandline and environment variables you have set so that I try to reproduce what you get.

@joerchan see my earlier comment, I hardly use Zephyr SDK. I may be wrong, but attaching my ninja verbose for your perusal. I piped my GCC version and "ninja --verbose".

build.log

@joerchan
Copy link
Contributor Author

@cvinayak Didn't see that comment. You are using arm-none-eabi-gcc from the ARCH package manager? It might not be the same build that you get from ARMs webpage. You shoud probably get that one instead.

@thomasstenersen
Copy link
Collaborator

@cvinayak, no special environment.

GNUARMEMB_TOOLCHAIN_PATH=/usr/bin/..
ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb

Attached build.log

@joerchan, I'm using the one built by Fedora. So not stock ARM build. Might be that the arch build does not enable -Waddress-of-packed-member by default?
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

@joerchan
Copy link
Contributor Author

@cvinayak @thomasstenersen AFAIK ARM maintains ARM support for GCC only on their website, not for different package managers. So I strongly recommend you switch to that one instead.

@carlescufi carlescufi assigned carlescufi and unassigned cvinayak Feb 14, 2020
@carlescufi
Copy link
Member

carlescufi commented Feb 14, 2020

I tested this both with Zephyr SDK 0.11.1:

$ ~/bin/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc --version
arm-zephyr-eabi-gcc (crosstool-NG 1.24.0.37-3f461da-dirty) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And with GNU Arm Embedded 9-2019-q4, as downloaded from here:

$ ~/bin/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Neither show any issues, and those are the officially supported toolchains for Arm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

6 participants