-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Not Prioritized
-
Code Generation Tools
-
CODEGEN-15157
-
-
default
The attached file has these lines ...
memcpy(fakehdr.srcIp, ((ipv4_header_t const *)ip)->src, 4); memcpy(fakehdr.dstIp, ((ipv4_header_t const *)ip)->dst, 4); fakehdr.zero = 0; fakehdr.protocol = protocol; fakehdr.len = (uint16_t)__builtin_bswap16(len); checksum = start(hd, len);
Focus on the assignments to the fields zero and protocol. They are 8-bit fields at byte offsets 8 and 9 in the structure.
Build it and disassemble.
$ tiarmclang -mcpu=cortex-r5 -mfloat-abi=hard -mfpu=vfpv3-d16 -mthumb -g -c -Os -save-temps -o file403.o file.c $ tiarmobjdump --source file403.o > dis403.txt
Inspect the disassembly. Find the 2nd bl instruction in the function checksum, which is the call to function start from the previous code fragment.
; memcpy(fakehdr.srcIp, ((ipv4_header_t const *)ip)->src, 4);
74: 68d0 ldr r0, [r2, #0xc]
; fakehdr.len = (uint16_t)__builtin_bswap16(len);
76: ba4c rev16 r4, r1
; memcpy(fakehdr.dstIp, ((ipv4_header_t const *)ip)->dst, 4);
78: 6912 ldr r2, [r2, #0x10]
; fakehdr.len = (uint16_t)__builtin_bswap16(len);
7a: f8ad 400a strh.w r4, [sp, #0xa]
; memcpy(fakehdr.srcIp, ((ipv4_header_t const *)ip)->src, 4);
7e: e9cd 0200 strd r0, r2, [sp]
; checksum = start(hd, len);
82: 4618 mov r0, r3
84: f7ff fffe bl 0x84 <checksum+0x84> @ imm = #-0x4
The assignments to fakehdr.zero and fakehdr.protocol are missing. Even though those memory locations are read in the function compute, called from the function start. The register sp has the base address of fakehdr. Focus on the str instructions and which bytes of the structure are written. The strh writes at offsets 10 and 11. The strd writes at offsets 0-7. The bytes at offsets 8-9 are never written. These bytes correspond to the location for the fields zero and protocol.
A similar experiment with version 5.0.0.STS has a similar result.