[cfe-dev] clang-built binary freeze with _FORTIFY_SOURCE=2

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Feb 17 05:58:07 PST 2014


On 17 February 2014 04:15, Sylvestre Ledru <sylvestre at debian.org> wrote:
> Hello,
>
> Playing with my rebuilds of Debian, I noticed that 149 packages timeout
> during the build (packages
> like gcc, firefox / iceweasel, llvm, mysql).
>
> I have been able to produce a small test case which shows the freeze.
> clang++ -o conftest -g  -O2  -D_FORTIFY_SOURCE=2 conftest.cpp
> (note that _FORTIFY_SOURCE=2 are added by Debian & Ubuntu build systems)
>
> --- conftest.cpp ---
> #include <stdlib.h>
> #include <unistd.h>
> #include <fcntl.h>
>
> int main ()
> {
>     char *data;
>     int  pagesize;
>     int fd, foo;
>     pagesize = getpagesize ();
>     fd = open ("conftest.mmap", O_RDWR);
>     data = (char *) malloc (pagesize);
>     foo = read (fd, data, pagesize);
> }
> ---------
> In the asm generated, clang will replace the call by __read_chk while
> g++ uses read.
> Any idea on how to fix that ?
>
> It seems related to this bug:
> http://llvm.org/bugs/show_bug.cgi?id=16821
>
> If we have a fix, i think it would be a nice backport to 3.4.1.

We don't have a fix. It looks like we have all that is needed in llvm
to get most cases implemented (see comment 15). It would still be
medium sized patch for clang. A bug compatible with gcc implementation
would be fairly hard given its strange semantics (only used if
inlined, never used if function pointer is used, etc). Hopefully these
are really just bugs and a saner implementation would work for
_FORTIFY_SOURCE=2.

Cheers,
Rafael



More information about the cfe-dev mailing list