0

[Reland] Stop using -std=gnu*

This reland includes a patch that fixes the AFL build with CFLAGS="-std=c11
-D_GNU_SOURCE".

BUG=427584
TBR=thakis,sbc

Change-Id: I9c3c52f4898a9ae1efc377802671ac44b79e9381
Reviewed-on: https://chromium-review.googlesource.com/1180170
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Jonathan Metzman <metzman@chromium.org>
Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584284}
This commit is contained in:
Tom Anderson
2018-08-18 02:07:36 +00:00
committed by Commit Bot
parent 23eec82220
commit 6009a54aab
10 changed files with 75 additions and 23 deletions
build/config/compiler
native_client_sdk/src/libraries/nacl_io
third_party

@ -550,16 +550,22 @@ config("compiler") {
cxx11_override = use_cxx11
}
# gnu11/gnu++11 instead of c11/c++11 is needed because some code uses typeof()
# (a GNU extension).
# TODO(thakis): Eventually switch this to c++11 instead,
# http://crbug.com/427584
cflags_c += [ "-std=gnu11" ]
# Since we build with -std=c* and not -std=gnu*, _GNU_SOURCE will not be
# defined by the compiler. However, lots of code relies on the non-standard
# features that _GNU_SOURCE enables, so define it manually.
defines += [ "_GNU_SOURCE" ]
cflags_c += [ "-std=c11" ]
if (cxx11_override) {
# Override Chromium's default for projects that wish to stay on C++11.
cflags_cc += [ "-std=gnu++11" ]
cflags_cc += [ "-std=c++11" ]
} else {
cflags_cc += [ "-std=gnu++14" ]
cflags_cc += [ "-std=c++14" ]
}
if (is_nacl) {
# Undefine __STRICT_ANSI__ to get non-standard features which would
# otherwise not be enabled by NaCl's sysroots.
cflags += [ "-U__STRICT_ANSI__" ]
}
} else if (!is_win && !is_nacl) {
if (target_os == "android") {

@ -82,7 +82,7 @@ EXTERN_C_BEGIN
#define WRAP(name) __nacl_irt_##name##_wrap
// Declare REAL function pointer.
#define DECLARE_REAL_PTR(name) typeof(__nacl_irt_##name) REAL(name);
#define DECLARE_REAL_PTR(name) __typeof__(__nacl_irt_##name) REAL(name);
// Assign the REAL function pointer.
#define ASSIGN_REAL_PTR(name) \
@ -90,10 +90,12 @@ EXTERN_C_BEGIN
REAL(name) = __nacl_irt_##name;
// Switch IRT's pointer to the REAL pointer
#define USE_REAL(name) __nacl_irt_##name = (typeof(__nacl_irt_##name))REAL(name)
#define USE_REAL(name) \
__nacl_irt_##name = (__typeof__(__nacl_irt_##name))REAL(name)
// Switch IRT's pointer to the WRAP function
#define USE_WRAP(name) __nacl_irt_##name = (typeof(__nacl_irt_##name))WRAP(name)
#define USE_WRAP(name) \
__nacl_irt_##name = (__typeof__(__nacl_irt_##name))WRAP(name)
#define EXPAND_SYMBOL_LIST_OPERATION(OP) \
OP(chdir); \

@ -32,18 +32,18 @@ EXTERN_C_BEGIN
// Declare REAL function pointer.
#define DECLARE_REAL_PTR(group, name) \
typeof(__libnacl_irt_##group.name) REAL(name);
__typeof__(__libnacl_irt_##group.name) REAL(name);
// Assign the REAL function pointer.
#define ASSIGN_REAL_PTR(group, name) REAL(name) = __libnacl_irt_##group.name;
// Switch IRT's pointer to the REAL pointer
#define USE_REAL(group, name) \
__libnacl_irt_##group.name = (typeof(REAL(name)))REAL(name);
__libnacl_irt_##group.name = (__typeof__(REAL(name)))REAL(name);
// Switch the IRT's pointer to the WRAP function
#define USE_WRAP(group, name) \
__libnacl_irt_##group.name = (typeof(REAL(name)))WRAP(name);
__libnacl_irt_##group.name = (__typeof__(REAL(name)))WRAP(name);
extern void __libnacl_irt_dev_filename_init(void);
extern void __libnacl_irt_dev_fdio_init(void);

@ -2,7 +2,7 @@ Name: American Fuzzy Lop
Short Name: AFL
URL: http://lcamtuf.coredump.cx/afl/
Version: 2.52b
Date: December 13, 2017
Date: August 17, 2018
License: Apache 2.0
License File: src/docs/COPYING
Security Critical: no
@ -20,3 +20,5 @@ Local Modifications:
- src/testcases/others/elf
- src/llvm_mode/afl-llvm-pass.so.cc
- src/dictionaries/
- patches/0001-fix-build-with-std-c11.patch
- Fix build with CFLAGS="-std=c11 -D_GNU_SOURCE"

@ -0,0 +1,27 @@
diff --git a/afl-fuzz.c b/afl-fuzz.c
index 01b4afef0ecc..f0d564a33037 100644
--- a/afl-fuzz.c
+++ b/afl-fuzz.c
@@ -23,7 +23,9 @@
#define AFL_MAIN
#define MESSAGES_TO_STDOUT
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#define _FILE_OFFSET_BITS 64
#include "config.h"
diff --git a/types.h b/types.h
index 784d3a7a286d..d24d1fdd97e8 100644
--- a/types.h
+++ b/types.h
@@ -78,7 +78,7 @@ typedef int64_t s64;
#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
#define MEM_BARRIER() \
- asm volatile("" ::: "memory")
+ __asm__ volatile("" ::: "memory")
#define likely(_x) __builtin_expect(!!(_x), 1)
#define unlikely(_x) __builtin_expect(!!(_x), 0)

@ -23,7 +23,9 @@
#define AFL_MAIN
#define MESSAGES_TO_STDOUT
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#define _FILE_OFFSET_BITS 64
#include "config.h"

@ -78,7 +78,7 @@ typedef int64_t s64;
#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
#define MEM_BARRIER() \
asm volatile("" ::: "memory")
__asm__ volatile("" ::: "memory")
#define likely(_x) __builtin_expect(!!(_x), 1)
#define unlikely(_x) __builtin_expect(!!(_x), 0)

@ -11,6 +11,7 @@ import cStringIO
import datetime
import os
import re
import subprocess
import sys
import tarfile
import urllib2
@ -127,6 +128,16 @@ def version_to_float(version):
return float(version)
def apply_patches():
afl_dir = os.path.join('third_party', 'afl')
patch_dir = os.path.join(afl_dir, 'patches')
src_dir = os.path.join(afl_dir, 'src')
for patch_file in os.listdir(patch_dir):
subprocess.check_output(
['patch', '-i',
os.path.join('..', 'patches', patch_file)], cwd=src_dir)
def update_afl(new_version):
"""
Update this version of AFL to newer version, new_version.
@ -142,14 +153,10 @@ def update_afl(new_version):
# Extract the tarball.
tarball = AflTarball(new_version)
tarball.download()
current_less_than_new = version_to_float(old_version) < version_to_float(
tarball.real_version)
assert current_less_than_new, (
'Trying to update from version {0} to {1}'.format(old_version,
tarball.real_version))
tarball.extract()
apply_patches()
readme.update(tarball.real_version)

@ -15,8 +15,10 @@ declare_args() {
if (!use_system_libdrm) {
config("libdrm_config") {
# Define _GNU_SOURCE for vasprintf use in xf86drm.c
defines = [ "_GNU_SOURCE" ]
# TODO(thomasanderson): Remove this hack once
# https://patchwork.kernel.org/patch/10545295/ lands.
defines = [ "typeof(x)=__typeof__(x)" ]
include_dirs = [
"src",
"src/include",

@ -16,6 +16,10 @@ if (!use_system_libwayland) {
"include/protocol",
"src/src",
]
# TODO(thomasanderson): Remove this once
# https://patchwork.freedesktop.org/patch/242086/ lands.
cflags = [ "-Wno-macro-redefined" ]
}
static_library("wayland_util") {