All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: Peter Zijlstra <peterz@infradead.org>,
	Vegard Nossum <vegard.nossum@oracle.com>
Cc: linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Luis R . Rodriguez" <mcgrof@kernel.org>,
	stable@vger.kernel.org, Ming Lei <ming.lei@canonical.com>,
	Steven Rostedt <srostedt@redhat.com>
Subject: Re: [PATCH 01/12] extarray: define helpers for arrays defined in linker scripts
Date: Wed, 19 Oct 2016 09:16:28 +0200	[thread overview]
Message-ID: <286773cc-54b3-4a4e-2891-befdb48ad3f8@suse.cz> (raw)
In-Reply-To: <20161017114517.GQ3117@twins.programming.kicks-ass.net>

On 10/17/2016, 01:45 PM, Peter Zijlstra wrote:
> And given GCC7 is still in development, this might be a good time to get
> a knob added for our benefit.

I tried and failed, see below. Citing from:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77964

(In reply to Jiri Slaby from comment #16)
> (In reply to Jakub Jelinek from comment #15)
> > lots of them that rely on pointer arithmetics being defined only
within the
> > same object.
>
> Sure, but the two pointers (taken implicitly of the arrays) are within the
> same object. So I do not see, why it wouldn't work? I.e. where exactly
this
> breaks the C specs?

No.  In C
extern struct builtin_fw __start_builtin_fw[];
extern struct builtin_fw __end_builtin_fw[];
declares two external arrays, thus they are two independent objects.  It
is like if you have:
int a[10];
int b[10];
in your program, although they might be allocated adjacent, such that
int *p = &a[10]; int *q = &b[0]; memcmp (&p, &q, sizeof (p)) == 0;
&b[0] - &a[0] is still UB.
What you do with __start_*/__end_* symbols is nothing you can define in
C, you need linker support or asm for that, and to use it without UB you
also need to use an optimization barrier that has been suggested.

==============================

> And given gcc 7 is to be released yet, can we have a switch to disable
this
> optimization?

This is nothing new in GCC 7, you've most likely just been extremely
lucky in the past that it happened to work as you expected.  Other
projects had to change similar UB code years ago.  It isn't just a
single optimization, but lots of them that rely on pointer arithmetics
being defined only within the same object.


-- 
js
suse labs

  parent reply	other threads:[~2016-10-19 14:40 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-16 15:16 [PATCH 00/12] external array access helpers Vegard Nossum
2016-10-16 15:16 ` [PATCH 01/12] extarray: define helpers for arrays defined in linker scripts Vegard Nossum
2016-10-17  7:04   ` Greg Kroah-Hartman
2016-10-17  8:33   ` Peter Zijlstra
2016-10-17  9:01     ` Jiri Slaby
2016-10-17  9:09       ` Peter Zijlstra
2016-10-17 11:27         ` Vegard Nossum
2016-10-17 11:45           ` Peter Zijlstra
2016-10-18  8:08             ` Vegard Nossum
2016-10-18 21:18               ` Luis R. Rodriguez
2016-10-19  8:18                 ` Richard Biener
2016-10-19  9:13                   ` Peter Zijlstra
2016-10-19  9:33                     ` Richard Biener
2016-10-19 10:25                       ` Peter Zijlstra
2016-10-19 11:11                         ` Richard Biener
2016-10-19 11:31                           ` Peter Zijlstra
2016-11-02 12:11                         ` Markus Trippelsdorf
2016-11-02 12:14                           ` Richard Biener
2016-11-02 15:02                             ` Linus Torvalds
2016-10-19  7:16             ` Jiri Slaby [this message]
2016-10-16 15:16 ` [PATCH 02/12] firmware: declare {__start,__end}_builtin_fw as external array Vegard Nossum
2016-10-16 15:16 ` [PATCH 03/12] ftrace: declare __{start,stop}_mcount_loc " Vegard Nossum
2016-10-16 15:16 ` [PATCH 04/12] tracing: declare __{start,stop}_{annotated_,}branch_profile " Vegard Nossum
2016-10-16 15:16 ` [PATCH 05/12] kprobes: declare __{start,stop}_kprobe_blacklist " Vegard Nossum
2016-10-17  5:53   ` Masami Hiramatsu
2016-10-16 15:16 ` [PATCH 06/12] tracing: declare __{start,stop}_ftrace_events " Vegard Nossum
2016-10-16 15:16 ` [PATCH 07/12] tracing: declare __{start,stop}_ftrace_enum_maps " Vegard Nossum
2016-10-16 15:16 ` [PATCH 08/12] tracing: declare __trace_bprintk_fmt/__tracepoint_str as external arrays Vegard Nossum
2016-10-16 15:16 ` [PATCH 09/12] tracing: declare __{start,stop}_syscalls_metadata as external array Vegard Nossum
2016-10-16 15:16 ` [PATCH 10/12] serial_core: declare __earlycon_table{,_end} " Vegard Nossum
2016-10-16 15:16 ` [PATCH 11/12] jump_label: declare jump table " Vegard Nossum
2016-10-16 16:25   ` Peter Zijlstra
2016-10-16 16:50     ` Vegard Nossum
2016-10-16 17:44       ` Peter Zijlstra
2016-10-17 21:33       ` Steven Rostedt
2016-10-16 15:16 ` [PATCH 12/12] dynamic debug: declare " Vegard Nossum
2016-10-16 16:14 ` [PATCH 00/12] external array access helpers Greg Kroah-Hartman
2016-10-16 17:05   ` Vegard Nossum
2016-10-17  7:02     ` Greg Kroah-Hartman
2016-10-17  6:26   ` Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=286773cc-54b3-4a4e-2891-befdb48ad3f8@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=ming.lei@canonical.com \
    --cc=peterz@infradead.org \
    --cc=srostedt@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vegard.nossum@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.