Page MenuHomeFreeBSD

amd64 kernel __storeload_barrier: quiet gcc -Warray-bounds
ClosedPublic

Authored by rlibby on Jun 22 2024, 5:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 8, 12:57 PM
Unknown Object (File)
Fri, Nov 8, 12:56 PM
Unknown Object (File)
Fri, Nov 8, 10:33 AM
Unknown Object (File)
Wed, Nov 6, 3:44 PM
Unknown Object (File)
Wed, Nov 6, 3:40 PM
Unknown Object (File)
Wed, Nov 6, 3:40 PM
Unknown Object (File)
Wed, Nov 6, 3:29 PM
Unknown Object (File)
Wed, Oct 23, 9:50 PM
Subscribers

Details

Summary

Use a constant input operand instead of an output operand to tell the
compiler about OFFSETOF_MONITORBUF. If we tell it we are writing to
*(u_int *)OFFSETOF_MONITORBUF, it rightly complains, but we aren't. The
memory clobber already covers the necessary semantics for the compiler.


This quiets around 142 warnings building amd64 GENERIC.

Test Plan

clang:

% llvm-objdump -d --disassemble-symbols=membarrier_action_seqcst /usr/obj/usr/src/freebsd/amd64.amd64/sys/GENERIC/kernel 

/usr/obj/usr/src/freebsd/amd64.amd64/sys/GENERIC/kernel:	file format elf64-x86-64

Disassembly of section .text:

ffffffff80b1d020 <membarrier_action_seqcst>:
ffffffff80b1d020: 55                   	pushq	%rbp
ffffffff80b1d021: 48 89 e5             	movq	%rsp, %rbp
ffffffff80b1d024: f0                   	lock
ffffffff80b1d025: 65 83 04 25 00 01 00 00 00   	addl	$0x0, %gs:0x100
ffffffff80b1d02e: 5d                   	popq	%rbp
ffffffff80b1d02f: c3                   	retq

gcc13:

% llvm-objdump -d --disassemble-symbols=membarrier_action_seqcst /usr/obj/gcc13/usr/src/freebsd/amd64.amd64/sys/GENERIC/kernel

/usr/obj/gcc13/usr/src/freebsd/amd64.amd64/sys/GENERIC/kernel:	file format elf64-x86-64

Disassembly of section .text:

ffffffff81448550 <membarrier_action_seqcst>:
ffffffff81448550: f0                   	lock
ffffffff81448551: 65 83 04 25 00 01 00 00 00   	addl	$0x0, %gs:0x100
ffffffff8144855a: c3                   	retq
ffffffff8144855b: 0f 1f 44 00 00       	nopl	(%rax,%rax)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

rlibby edited the test plan for this revision. (Show Details)

Would you please show the gcc warning, to satisfy my curiosity?

This revision is now accepted and ready to land.Jun 23 2024, 2:47 AM
In D45694#1042256, @kib wrote:

Would you please show the gcc warning, to satisfy my curiosity?

Sure, here's an example from gcc13 for membarrier_action_seqcst():

In file included from /usr/src/freebsd-branches/main-push/sys/sys/systm.h:45,
                 from /usr/src/freebsd-branches/main-push/sys/kern/kern_membarrier.c:30:
In function '__storeload_barrier',
    inlined from 'atomic_thread_fence_seq_cst' at ./machine/atomic.h:352:2,
    inlined from 'membarrier_action_seqcst' at /usr/src/freebsd-branches/main-push/sys/kern/kern_membarrier.c:59:2:
./machine/atomic.h:298:9: warning: array subscript 0 is outside array bounds of 'u_int[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
  298 |         __asm __volatile("lock; addl $0,%%gs:%0"
      |         ^~~~~
In function 'membarrier_action_seqcst':
cc1: note: source object is likely at address zero
In function '__storeload_barrier',
    inlined from 'atomic_thread_fence_seq_cst' at ./machine/atomic.h:352:2,
    inlined from 'membarrier_action_seqcst' at /usr/src/freebsd-branches/main-push/sys/kern/kern_membarrier.c:59:2:
./machine/atomic.h:298:9: warning: array subscript 0 is outside array bounds of 'u_int[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
In function 'membarrier_action_seqcst':
cc1: note: source object is likely at address zero

I copied the meta file here, but it's more of the same:
https://people.freebsd.org/~rlibby/gcc13-kern_membarrier.o.meta

It looks like the warning gets issued twice per call so the 142 warnings might be just 71 sites.