public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm
@ 2004-09-07 11:35 matz at suse dot de
  2004-09-07 15:25 ` [Bug inline-asm/17346] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: matz at suse dot de @ 2004-09-07 11:35 UTC (permalink / raw)
  To: gcc-bugs

The linux kernel has a file asm-context.c, which is used to get hold 
of several offsets inside assembler.  For this inline asm is used to 
place the offsets directly into the assembler output, which later is parsed. 
A testcase is this: 
------------------------------------- 
struct A { int a, b; }; 
void foo(void) 
{ __asm volatile ("%0" : : "i" ((long)&((struct A*)0)->b)); } 
------------------------------------- 
 
The problem is, that the expression (T*)0->b is not thought to be constant 
anymore, and is placed inside a register.  The "i" constraints require a 
constant of course, so we get this error message when compiling the above: 
  foo.c:3: warning: asm operand 0 probably doesn't match constraints 
  foo.c:3: error: impossible constraint in `asm' 
 
Using __builtin_offsetof would fix this particular instance, but I think 
that the expression really should be taken as constant by the optimizers.

-- 
           Summary: linux kernel: handwritten offsetof break inline asm
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matz at suse dot de
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
@ 2004-09-07 15:25 ` pinskia at gcc dot gnu dot org
  2004-09-07 16:18 ` matz at suse dot de
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-07 15:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-07 15:25 -------
Nope use offsetof and not some crazy stuff, sorry.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
  2004-09-07 15:25 ` [Bug inline-asm/17346] " pinskia at gcc dot gnu dot org
@ 2004-09-07 16:18 ` matz at suse dot de
  2004-09-07 16:27 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: matz at suse dot de @ 2004-09-07 16:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2004-09-07 16:17 -------
Huh?  This _is_ to what offsetof in the kernel expands, if you would be so 
kind to read what I wrote.  The kernels in the wild are not using 
__builtin_offsetof, but instead this self-written idiom, which had to be used 
before __builtin_offsetof was invented.  So I very much think, that this 
idiom would be better recognized as constant, which in fact in C it is. 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
  2004-09-07 15:25 ` [Bug inline-asm/17346] " pinskia at gcc dot gnu dot org
  2004-09-07 16:18 ` matz at suse dot de
@ 2004-09-07 16:27 ` pinskia at gcc dot gnu dot org
  2004-09-07 16:32 ` matz at suse dot de
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-07 16:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-07 16:26 -------
Actually this is not a constant by defintion of the C standard at all....
This was an undocumented extension which was removed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (2 preceding siblings ...)
  2004-09-07 16:27 ` pinskia at gcc dot gnu dot org
@ 2004-09-07 16:32 ` matz at suse dot de
  2004-09-07 16:38 ` jsm at polyomino dot org dot uk
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: matz at suse dot de @ 2004-09-07 16:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2004-09-07 16:32 -------
Okay, let's break compiling the kernels.  I've enough. 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (3 preceding siblings ...)
  2004-09-07 16:32 ` matz at suse dot de
@ 2004-09-07 16:38 ` jsm at polyomino dot org dot uk
  2004-09-07 18:22 ` zack at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-09-07 16:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-09-07 16:38 -------
Subject: Re:  linux kernel: handwritten offsetof break
 inline asm

On Tue, 7 Sep 2004, pinskia at gcc dot gnu dot org wrote:

> Actually this is not a constant by defintion of the C standard at all....
> This was an undocumented extension which was removed.

Inline asm operands are not a place to be pedantic about the standard 
definition of constant expressions.  There, you *want* "anything the 
compiler can optimise to a constant" to be constant.  So there is a 
regression in what the compiler can optimise to be constant.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (4 preceding siblings ...)
  2004-09-07 16:38 ` jsm at polyomino dot org dot uk
@ 2004-09-07 18:22 ` zack at gcc dot gnu dot org
  2004-09-09  3:23 ` [Bug inline-asm/17346] [3.5 Regression] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: zack at gcc dot gnu dot org @ 2004-09-07 18:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From zack at gcc dot gnu dot org  2004-09-07 18:22 -------
reopening due to degree of controversy.

I have no opinion on whether or not this is a good idea, but as a technical
observation, I don't see why the C front end couldn't smash &((T *)0)->M to
__builtin_offsetof(T, M) before the optimizers can choke on it.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] [3.5 Regression] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (5 preceding siblings ...)
  2004-09-07 18:22 ` zack at gcc dot gnu dot org
@ 2004-09-09  3:23 ` pinskia at gcc dot gnu dot org
  2004-09-09 12:23 ` giovannibajo at libero dot it
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-09  3:23 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
            Summary|linux kernel: handwritten   |[3.5 Regression] linux
                   |offsetof break inline asm   |kernel: handwritten offsetof
                   |                            |break inline asm
   Target Milestone|---                         |3.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] [3.5 Regression] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (6 preceding siblings ...)
  2004-09-09  3:23 ` [Bug inline-asm/17346] [3.5 Regression] " pinskia at gcc dot gnu dot org
@ 2004-09-09 12:23 ` giovannibajo at libero dot it
  2004-09-09 12:48 ` matz at suse dot de
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-09 12:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-09-09 12:23 -------
Notice that if the kernel was using the macro offsetof() and not directly its 
expansion, it would always compile no matter how much we change the internals.

Anyway, I agre with JSM that we could have an enhancement where we try to fold 
things to constants in inline-asms as much as we can.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |3.5.0
      Known to work|                            |3.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-09-09 12:23:16
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] [3.5 Regression] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (7 preceding siblings ...)
  2004-09-09 12:23 ` giovannibajo at libero dot it
@ 2004-09-09 12:48 ` matz at suse dot de
  2004-09-09 16:28 ` jsm at polyomino dot org dot uk
  2004-09-11 17:46 ` [Bug inline-asm/17346] [4.0 " pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: matz at suse dot de @ 2004-09-09 12:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2004-09-09 12:48 -------
The kernel does use offsetof().  But of course it has its own headers, 
defining this macro to the usual construct, instead of using 
__builtin_offsetof (which didn't exist in older compilers).  I was merely 
expanding the offsetof macro in the testcase by hand, in order to make it 
visible, where exactly it breaks. 
 
And I would extend this to not just const-fold in asms.  There is no reason 
to not do this optimization also outside.  There is enough code out there 
which still uses the legacy definition of offsetof.  Why pessimize it? 
(This doesn't mean that this construct should be regarded as a constant 
in the language sense.  My point was, that it does boil down to a constant, 
no matter what the language says). 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] [3.5 Regression] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (8 preceding siblings ...)
  2004-09-09 12:48 ` matz at suse dot de
@ 2004-09-09 16:28 ` jsm at polyomino dot org dot uk
  2004-09-11 17:46 ` [Bug inline-asm/17346] [4.0 " pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-09-09 16:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-09-09 16:28 -------
Subject: Re:  [3.5 Regression] linux kernel: handwritten
 offsetof break inline asm

On Thu, 9 Sep 2004, matz at suse dot de wrote:

> The kernel does use offsetof().  But of course it has its own headers, 
> defining this macro to the usual construct, instead of using 
> __builtin_offsetof (which didn't exist in older compilers).  I was merely 
> expanding the offsetof macro in the testcase by hand, in order to make it 
> visible, where exactly it breaks. 

The compiler's versions of the headers required of freestanding 
implementations are mostly intended to be usable for non-userspace code.  
(If using <limits.h>, you will need to provide your own replacement for 
libc's one which GCC's includes with #include_next, or disable it by 
defining _LIBC_LIMITS_H_.)

> And I would extend this to not just const-fold in asms.  There is no reason 
> to not do this optimization also outside.  There is enough code out there 
> which still uses the legacy definition of offsetof.  Why pessimize it? 
> (This doesn't mean that this construct should be regarded as a constant 
> in the language sense.  My point was, that it does boil down to a constant, 
> no matter what the language says). 

We should optimise in all cases, at the various stages of compilation at 
which it makes sense, and this should be independent of the checks on what 
is sufficiently constant where the standards require a constant.  My model 
of constant expressions <http://www.srcf.ucam.org/~jsm28/gcc/#const> 
defines the given expression as being an address constant of integer type, 
so usable in initializers though not where integer constant expressions 
are required (case labels, enum values, bit-field widths, initializer 
designators, null pointer constants), whereas __builtin_offsetof will 
expand to an actual integer constant expression usable in all those 
places.  But the expression should be optimised to a constant early in 
compilation (no later than an early pass on GIMPLE).

Because of the inherently implementation-dependent nature of asm 
statements, whether something is an integer constant when an asm needs an 
integer constant shouldn't be checked based on standard rules for constant 
expressions, but on whether it can be optimised to a constant.  How much 
optimisation should be used - whether e.g. it shouldn't be checked until 
after SSA constant propagation - I'm not sure; either you have the problem 
of emitting diagnostics after what should be a valid translation unit has 
been passed off from the front end to the middle end in GIMPLE, or you 
have the problem of not accepting cases that may be useful to some users 
of asm statements.  There is even a case for accepting the strange sorts 
of constants Geoff Keating mentioned in 
<http://gcc.gnu.org/ml/gcc/2004-08/msg00812.html>, for appropriate asm 
constraints, if the assembler might accept them, to provide the window for 
people knowing what strange things their assembler considers OK in a given 
context to use them.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug inline-asm/17346] [4.0 Regression] linux kernel: handwritten offsetof break inline asm
  2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
                   ` (9 preceding siblings ...)
  2004-09-09 16:28 ` jsm at polyomino dot org dot uk
@ 2004-09-11 17:46 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-11 17:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-11 17:46 -------
"Fixed" by:

        PR c/17396
        * c-typeck.c (build_unary_op): Add legacy offsetof hack.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
      Known to fail|4.0                         |4.0.0
         Resolution|                            |FIXED
            Summary|[3.5 Regression] linux      |[4.0 Regression] linux
                   |kernel: handwritten offsetof|kernel: handwritten offsetof
                   |break inline asm            |break inline asm


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17346


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-09-11 17:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-07 11:35 [Bug inline-asm/17346] New: linux kernel: handwritten offsetof break inline asm matz at suse dot de
2004-09-07 15:25 ` [Bug inline-asm/17346] " pinskia at gcc dot gnu dot org
2004-09-07 16:18 ` matz at suse dot de
2004-09-07 16:27 ` pinskia at gcc dot gnu dot org
2004-09-07 16:32 ` matz at suse dot de
2004-09-07 16:38 ` jsm at polyomino dot org dot uk
2004-09-07 18:22 ` zack at gcc dot gnu dot org
2004-09-09  3:23 ` [Bug inline-asm/17346] [3.5 Regression] " pinskia at gcc dot gnu dot org
2004-09-09 12:23 ` giovannibajo at libero dot it
2004-09-09 12:48 ` matz at suse dot de
2004-09-09 16:28 ` jsm at polyomino dot org dot uk
2004-09-11 17:46 ` [Bug inline-asm/17346] [4.0 " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).