From abba6ef6fac577e947334ef5bce13584912f82a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?= Date: Tue, 22 Jan 2013 13:44:34 +0100 Subject: perf: Fix build inside the Android source tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernhard Rosenkränzer --- include/uapi/asm-generic/posix_types.h | 5 ++ tools/lib/traceevent/Makefile | 1 + tools/perf/Makefile | 8 +- tools/perf/compat-android.h | 133 +++++++++++++++++++++++++++++++++ tools/perf/util/util.h | 2 + 5 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 tools/perf/compat-android.h diff --git a/include/uapi/asm-generic/posix_types.h b/include/uapi/asm-generic/posix_types.h index fe74fccf18d..85bbd1160d5 100644 --- a/include/uapi/asm-generic/posix_types.h +++ b/include/uapi/asm-generic/posix_types.h @@ -1,7 +1,12 @@ #ifndef __ASM_GENERIC_POSIX_TYPES_H #define __ASM_GENERIC_POSIX_TYPES_H +#if !defined(__arm__) && !defined(__aarch64__) #include +#else +#include +#endif + /* * This file is generally used by user-level software, so you need to * be a little careful about namespace pollution etc. diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile index a20e3203343..e00ce22eec4 100644 --- a/tools/lib/traceevent/Makefile +++ b/tools/lib/traceevent/Makefile @@ -130,6 +130,7 @@ CFLAGS ?= -g -Wall # Append required CFLAGS override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) override CFLAGS += $(udis86-flags) -D_GNU_SOURCE +override CFLAGS += $(ANDROID_CFLAGS) ifeq ($(VERBOSE),1) Q = diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 891bc77bdb2..236333beb74 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -103,7 +103,7 @@ ifdef PARSER_DEBUG PARSER_DEBUG_CFLAGS := -DPARSER_DEBUG endif -CFLAGS = -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS) +CFLAGS = $(ANDROID_CFLAGS) -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS) EXTLIBS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE ALL_LDFLAGS = $(LDFLAGS) @@ -204,7 +204,8 @@ ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y) BIONIC := 1 EXTLIBS := $(filter-out -lrt,$(EXTLIBS)) EXTLIBS := $(filter-out -lpthread,$(EXTLIBS)) - BASIC_CFLAGS += -I. + ANDROID_CFLAGS += -I. -DANDROID -DHAVE_STRLCPY -include $(CURDIR)/compat-android.h + CFLAGS += -I. -DANDROID -DHAVE_STRLCPY -include $(CURDIR)/compat-android.h endif # Guard against environment variables @@ -862,6 +863,7 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group +ALL_CFLAGS += $(ANDROID_CFLAGS) ALL_CFLAGS += $(BASIC_CFLAGS) ALL_CFLAGS += $(ARCH_CFLAGS) ALL_LDFLAGS += $(BASIC_LDFLAGS) @@ -1006,7 +1008,7 @@ $(LIB_FILE): $(LIB_OBJS) # libtraceevent.a $(LIBTRACEEVENT): - $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libtraceevent.a + $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) ANDROID_CFLAGS="$(ANDROID_CFLAGS)" O=$(OUTPUT) libtraceevent.a $(LIBTRACEEVENT)-clean: $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) clean diff --git a/tools/perf/compat-android.h b/tools/perf/compat-android.h new file mode 100644 index 00000000000..b76adae2773 --- /dev/null +++ b/tools/perf/compat-android.h @@ -0,0 +1,133 @@ +/* Android compatibility header + * Provides missing bits in Bionic on Android, ignored + * on regular Linux. + * + * Written by Bernhard.Rosenkranzer@linaro.org + * + * Released into the public domain. Do with this file + * whatever you want. + */ +#ifdef ANDROID +/* Bionic has its own idea about ALIGN, and kills other definitions. + * Done outside the multiple-inclusion wrapper to make sure we + * can override Bionic's ALIGN by simply including compat-android.h + * again after including Bionic headers. + */ +#undef ALIGN +#undef __ALIGN_MASK +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) + +#ifndef _COMPAT_ANDROID_H_ +#define _COMPAT_ANDROID_H_ 1 +/* Stuff Bionic assumes to be present, but that doesn't exist + * anymore after the uabi kernel header reorg + */ +#include +#include +typedef unsigned short __kernel_nlink_t; +typedef intptr_t phys_addr_t; +#include +typedef uint32_t u32; +typedef uint64_t u64; +#ifndef CONFIG_DRAM_BASEUL +#ifdef CONFIG_DRAM_BASE +#define CONFIG_DRAM_BASEUL UL(CONFIG_DRAM_BASE) +#else +#define CONFIG_DRAM_BASEUL 0 +#endif +#endif +#define __deprecated + +#include +#undef BITS_PER_LONG /* Something seems to define this incorrectly */ +#define BITS_PER_LONG _BITSIZE + +#include +#include +#include /* for PAGE_SIZE */ +#include /* for winsize */ + +#ifndef __WORDSIZE +#define __WORDSIZE _BITSIZE +#endif + +#ifndef roundup +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#endif + +#ifndef __force +#define __force +#endif + +#ifndef __le32 +#define __le32 uint32_t +#endif + +#ifndef FD_SET +#define FD_SET(fd, fdsetp) (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] |= (1<<((fd) & 31))) +#define FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof (*(fd_set *)(fdsetp)))) +#endif + +/* Assorted functions that are missing from Bionic */ +/* Android prior to 4.2 lacks psignal(). + * What we're doing here is fairly evil - but necessary since + * Bionic doesn't export any version identifier or the likes. + * We do know that 4.2 is the version introducing psignal() and + * also KLOG_CONSOLE_OFF -- completely unrelated, but something + * we can check for... + */ +#include +#ifndef KLOG_CONSOLE_OFF +static void psignal(int sig, const char *s) +{ + if(sig >= 0 && sig < NSIG) { + if(s) + fprintf(stderr, "%s: %s\n", s, sys_siglist[sig]); + else + fprintf(stderr, "%s\n", sys_siglist[sig]); + } else { + if(s) + fprintf(stderr, "%s: invalid signal\n", s); + else + fputs("invalid signal\n", stderr); + } +} +#endif + +static ssize_t getline(char **lineptr, size_t *n, FILE *stream) +{ + size_t ret = 0; + + if (!lineptr || !n || !stream) + return -1; + + if(!*lineptr) { + *n = 128; + *lineptr = (char*)malloc(*n); + if(!*lineptr) + return -1; + } + + while(!feof(stream) && !ferror(stream)) { + int c; + if(ret == *n) { + *n += 128; + *lineptr = (char*)realloc(*lineptr, *n); + if(!*lineptr) { + *n = 0; + return -1; + } + } + c = fgetc(stream); + if(c == EOF) + break; + *lineptr[ret++] = c; + if(c == '\n') + break; + } + *lineptr[ret] = 0; + return ret; +} +#endif +#endif diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index c2330918110..e7cefc8f7d1 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -256,11 +256,13 @@ void event_attr_init(struct perf_event_attr *attr); * *not* considered a power of two. */ +#ifndef _LINUX_LOG2_H /* is_power_of_2 is defined here too, and Bionic drags in that header */ static inline __attribute__((const)) bool is_power_of_2(unsigned long n) { return (n != 0 && ((n & (n - 1)) == 0)); } +#endif size_t hex_width(u64 v); int hex2u64(const char *ptr, u64 *val); -- cgit v1.2.3