Quantcast

Re: Clang incorrectly optimizing out for conditional in Linux

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang incorrectly optimizing out for conditional in Linux

Daniel Marjamäki via cfe-dev
I filed an issue with the Kernel (here https://bugzilla.kernel.org/show_bug.cgi?id=195235) to capture this issue.  Hopefully this is something that they will fix!  I'll note that my suggested answer assumes they want the behavior to remain the same, though I'm not sure that is what they MEANT.

-Erich

On 4/3/17 9:33 AM, Derrick McKee via cfe-dev wrote:

> Hi,
>
> I am trying to get the Linux kernel to compile and boot using clang.
> The code compiles fine, but the kernel does not boot.  It looks like
> the following macro in mm/vmalloc.c (line 650) is optimizing out the
> exit condition on the for loop:
>
> #define llist_for_each_entry(pos, node, member)             \
>     for ((pos) = llist_entry((node), typeof(*(pos)), member);   \
>          &(pos)->member != NULL;

This comparison is tautologically true because it'd be UB to construct the address if pos were null, and true otherwise.


Jon

         \
>          (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member))
>

snip

> --
> Derrick McKee
> Ph.D. Student at Purdue University
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

--
Jon Roelofs
[hidden email]
CodeSourcery / Mentor Embedded


------------------------------

Subject: Digest Footer

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


------------------------------

End of cfe-dev Digest, Vol 118, Issue 8
***************************************
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang incorrectly optimizing out for conditional in Linux

Daniel Marjamäki via cfe-dev
On 3 Apr 2017, at 20:24, Keane, Erich via cfe-dev <[hidden email]> wrote:
>
> I filed an issue with the Kernel (here https://bugzilla.kernel.org/show_bug.cgi?id=195235) to capture this issue.  Hopefully this is something that they will fix!  I'll note that my suggested answer assumes they want the behavior to remain the same, though I'm not sure that is what they MEANT.

As I recall, this particular kernel idiom is one that caused GCC to add an extra flag to restrict their optimisations, because rewriting Linux in C was harder than hacking the compiler to support Linux-flavoured almost-C, so I wouldn’t hold out much hope for Linux fixing the code - this is far from the only place that this idiom occurs and has been the cause of at least one security vulnerability.  

David

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang incorrectly optimizing out for conditional in Linux

Daniel Marjamäki via cfe-dev
Well Blarg, that is disappointing.  In THIS case, I at least have a hope, the original implementer and I share an organization, so hopefully he'll be willing to fix it out of internal good will :)

-----Original Message-----
From: Dr D. Chisnall [mailto:[hidden email]] On Behalf Of David Chisnall
Sent: Tuesday, April 4, 2017 1:01 AM
To: Keane, Erich <[hidden email]>
Cc: [hidden email]; [hidden email]; [hidden email]; [hidden email]
Subject: Re: [cfe-dev] Clang incorrectly optimizing out for conditional in Linux

On 3 Apr 2017, at 20:24, Keane, Erich via cfe-dev <[hidden email]> wrote:
>
> I filed an issue with the Kernel (here https://bugzilla.kernel.org/show_bug.cgi?id=195235) to capture this issue.  Hopefully this is something that they will fix!  I'll note that my suggested answer assumes they want the behavior to remain the same, though I'm not sure that is what they MEANT.

As I recall, this particular kernel idiom is one that caused GCC to add an extra flag to restrict their optimisations, because rewriting Linux in C was harder than hacking the compiler to support Linux-flavoured almost-C, so I wouldn’t hold out much hope for Linux fixing the code - this is far from the only place that this idiom occurs and has been the cause of at least one security vulnerability.  

David

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang incorrectly optimizing out for conditional in Linux

Daniel Marjamäki via cfe-dev
In the meanwhile, were you able to talk with the implementer about your proposed change, Erich?  If you and the implementer agree on your fix, maybe I can add it to my source and get going on my work.

On Tue, Apr 4, 2017 at 11:25 AM Keane, Erich <[hidden email]> wrote:
Well Blarg, that is disappointing.  In THIS case, I at least have a hope, the original implementer and I share an organization, so hopefully he'll be willing to fix it out of internal good will :)

-----Original Message-----
From: Dr D. Chisnall [mailto:[hidden email]] On Behalf Of David Chisnall
Sent: Tuesday, April 4, 2017 1:01 AM
To: Keane, Erich <[hidden email]>
Cc: [hidden email]; [hidden email]; [hidden email]; [hidden email]
Subject: Re: [cfe-dev] Clang incorrectly optimizing out for conditional in Linux

On 3 Apr 2017, at 20:24, Keane, Erich via cfe-dev <[hidden email]> wrote:
>
> I filed an issue with the Kernel (here https://bugzilla.kernel.org/show_bug.cgi?id=195235) to capture this issue.  Hopefully this is something that they will fix!  I'll note that my suggested answer assumes they want the behavior to remain the same, though I'm not sure that is what they MEANT.

As I recall, this particular kernel idiom is one that caused GCC to add an extra flag to restrict their optimisations, because rewriting Linux in C was harder than hacking the compiler to support Linux-flavoured almost-C, so I wouldn’t hold out much hope for Linux fixing the code - this is far from the only place that this idiom occurs and has been the cause of at least one security vulnerability.

David

--
Derrick McKee
Ph.D. Student at Purdue University

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clang incorrectly optimizing out for conditional in Linux

Daniel Marjamäki via cfe-dev

I was not, I sent him an email, but he and I are in different hemispheres, so we likely are going to have a few days lag.

 

From: Derrick McKee [mailto:[hidden email]]
Sent: Tuesday, April 4, 2017 9:14 AM
To: Keane, Erich <[hidden email]>; David Chisnall <[hidden email]>
Cc: [hidden email]; [hidden email]; [hidden email]
Subject: Re: [cfe-dev] Clang incorrectly optimizing out for conditional in Linux

 

In the meanwhile, were you able to talk with the implementer about your proposed change, Erich?  If you and the implementer agree on your fix, maybe I can add it to my source and get going on my work.

 

On Tue, Apr 4, 2017 at 11:25 AM Keane, Erich <[hidden email]> wrote:

Well Blarg, that is disappointing.  In THIS case, I at least have a hope, the original implementer and I share an organization, so hopefully he'll be willing to fix it out of internal good will :)

-----Original Message-----
From: Dr D. Chisnall [mailto:[hidden email]] On Behalf Of David Chisnall
Sent: Tuesday, April 4, 2017 1:01 AM
To: Keane, Erich <[hidden email]>
Cc: [hidden email]; [hidden email]; [hidden email]; [hidden email]
Subject: Re: [cfe-dev] Clang incorrectly optimizing out for conditional in Linux

On 3 Apr 2017, at 20:24, Keane, Erich via cfe-dev <[hidden email]> wrote:
>
> I filed an issue with the Kernel (here https://bugzilla.kernel.org/show_bug.cgi?id=195235) to capture this issue.  Hopefully this is something that they will fix!  I'll note that my suggested answer assumes they want the behavior to remain the same, though I'm not sure that is what they MEANT.

As I recall, this particular kernel idiom is one that caused GCC to add an extra flag to restrict their optimisations, because rewriting Linux in C was harder than hacking the compiler to support Linux-flavoured almost-C, so I wouldn’t hold out much hope for Linux fixing the code - this is far from the only place that this idiom occurs and has been the cause of at least one security vulnerability.

David

--

Derrick McKee
Ph.D. Student at Purdue University


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...