2011-01-24 00:56:40 -08:00
|
|
|
#
|
2012-05-21 04:12:37 -07:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-01-24 00:56:40 -08:00
|
|
|
|
2012-08-04 11:26:44 -07:00
|
|
|
DEPTH = @DEPTH@
|
2011-01-24 00:56:40 -08:00
|
|
|
topsrcdir = @top_srcdir@
|
|
|
|
srcdir = @srcdir@
|
|
|
|
VPATH = @srcdir@
|
|
|
|
|
|
|
|
include $(DEPTH)/config/autoconf.mk
|
|
|
|
|
|
|
|
INTERNAL_TOOLS = 1
|
|
|
|
|
|
|
|
HOST_PROGRAM = elfhack
|
|
|
|
NO_DIST_INSTALL = 1
|
2011-08-28 22:34:12 -07:00
|
|
|
NO_PROFILE_GUIDED_OPTIMIZE = 1
|
2011-01-24 00:56:40 -08:00
|
|
|
|
2011-04-15 02:03:17 -07:00
|
|
|
VPATH += $(topsrcdir)/build
|
|
|
|
|
2011-01-24 00:56:40 -08:00
|
|
|
HOST_CPPSRCS = \
|
|
|
|
elf.cpp \
|
|
|
|
elfhack.cpp \
|
|
|
|
$(NULL)
|
|
|
|
|
2011-01-28 00:22:58 -08:00
|
|
|
OS_CXXFLAGS := $(filter-out -fno-exceptions,$(OS_CXXFLAGS)) -fexceptions
|
2011-01-24 00:56:40 -08:00
|
|
|
|
|
|
|
ifneq (,$(filter %86,$(TARGET_CPU)))
|
|
|
|
CPU := x86
|
|
|
|
else
|
2011-01-28 00:22:59 -08:00
|
|
|
ifneq (,$(filter arm%,$(TARGET_CPU)))
|
|
|
|
CPU := arm
|
|
|
|
else
|
2011-01-24 00:56:40 -08:00
|
|
|
CPU := $(TARGET_CPU)
|
|
|
|
endif
|
2011-01-28 00:22:59 -08:00
|
|
|
endif
|
2011-01-24 00:56:40 -08:00
|
|
|
|
|
|
|
CSRCS := \
|
|
|
|
inject/$(CPU).c \
|
|
|
|
inject/$(CPU)-noinit.c \
|
2012-08-09 07:34:26 -07:00
|
|
|
test-ctors.c \
|
|
|
|
test-array.c \
|
2011-01-24 00:56:40 -08:00
|
|
|
$(NULL)
|
|
|
|
|
2011-08-28 22:34:02 -07:00
|
|
|
ifndef CROSS_COMPILE
|
|
|
|
CSRCS += dummy.c
|
|
|
|
endif
|
2011-01-24 00:56:40 -08:00
|
|
|
|
2011-08-29 10:21:22 -07:00
|
|
|
WRAP_LDFLAGS=
|
2011-08-09 00:05:49 -07:00
|
|
|
|
2011-08-28 22:34:02 -07:00
|
|
|
include $(topsrcdir)/config/rules.mk
|
|
|
|
|
2012-08-09 07:34:26 -07:00
|
|
|
test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX): %$(DLL_SUFFIX): %.$(OBJ_SUFFIX) elfhack $(filter inject/%,$(CSRCS:.c=.$(OBJ_SUFFIX)))
|
|
|
|
$(MKSHLIB) $(LDFLAGS) $< -nostartfiles
|
2011-01-28 00:22:58 -08:00
|
|
|
@echo ===
|
|
|
|
@echo === If you get failures below, please file a bug describing the error
|
|
|
|
@echo === and your environment \(compiler and linker versions\), and use
|
|
|
|
@echo === --disable-elf-hack until this is fixed.
|
|
|
|
@echo ===
|
2012-08-09 07:34:26 -07:00
|
|
|
# Fail if the library doesn't have $(DT_TYPE) .dynamic info
|
|
|
|
$(TOOLCHAIN_PREFIX)readelf -d $@ | grep '($(DT_TYPE))'
|
2011-01-28 00:22:58 -08:00
|
|
|
@rm -f $@.bak
|
2012-02-20 23:08:41 -08:00
|
|
|
$(CURDIR)/elfhack -b -f $@
|
2011-01-24 00:56:40 -08:00
|
|
|
# Fail if the backup file doesn't exist
|
|
|
|
[ -f "$@.bak" ]
|
|
|
|
# Fail if the new library doesn't contain less relocations
|
2012-08-09 07:34:26 -07:00
|
|
|
[ $$($(TOOLCHAIN_PREFIX)objdump -R $@.bak | wc -l) -gt $$(objdump -R $@ | wc -l) ]
|
2011-01-24 00:56:40 -08:00
|
|
|
|
2012-08-09 07:34:26 -07:00
|
|
|
test-array$(DLL_SUFFIX): DT_TYPE=INIT_ARRAY
|
|
|
|
test-ctors$(DLL_SUFFIX): DT_TYPE=INIT
|
2011-07-28 00:05:15 -07:00
|
|
|
|
2012-08-09 07:34:26 -07:00
|
|
|
.PRECIOUS: test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX)
|
2011-08-09 00:05:49 -07:00
|
|
|
|
2012-08-09 07:34:26 -07:00
|
|
|
GARBAGE += test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX) test-array$(DLL_SUFFIX).bak test-ctors$(DLL_SUFFIX).bak
|
|
|
|
|
|
|
|
libs:: test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX)
|
2011-08-09 00:05:49 -07:00
|
|
|
|
|
|
|
ifndef CROSS_COMPILE
|
2012-08-09 07:34:26 -07:00
|
|
|
dummy: dummy.$(OBJ_SUFFIX)
|
2011-05-17 00:34:20 -07:00
|
|
|
$(CC) -o $@ $^ $(LDFLAGS)
|
2011-01-24 00:56:40 -08:00
|
|
|
|
|
|
|
libs:: dummy
|
|
|
|
# Will either crash or return exit code 1 if elfhack is broken
|
2012-08-09 07:34:26 -07:00
|
|
|
LD_PRELOAD=$(CURDIR)/test-array$(DLL_SUFFIX) $(CURDIR)/dummy
|
|
|
|
LD_PRELOAD=$(CURDIR)/test-ctors$(DLL_SUFFIX) $(CURDIR)/dummy
|
2011-01-24 00:56:40 -08:00
|
|
|
|
2011-08-09 00:05:49 -07:00
|
|
|
GARBAGE += dummy
|
2011-01-24 00:56:40 -08:00
|
|
|
endif
|
|
|
|
|
|
|
|
inject:
|
|
|
|
$(NSINSTALL) -D $@
|
|
|
|
|
2012-08-09 07:34:24 -07:00
|
|
|
inject/%.c: inject.c $(call mkdir_deps,inject)
|
2011-01-24 00:56:40 -08:00
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
GARBAGE_DIRS += inject
|
|
|
|
|
2011-02-02 15:14:43 -08:00
|
|
|
inject/%.$(OBJ_SUFFIX): DEFINES += -DBITS=$(if $(HAVE_64BIT_OS),64,32)
|
2011-02-02 15:15:20 -08:00
|
|
|
inject/%.$(OBJ_SUFFIX): CFLAGS := -O2 -fno-stack-protector $(filter -m% -I%,$(CFLAGS))
|
2011-02-02 15:14:43 -08:00
|
|
|
inject/$(CPU)-noinit.$(OBJ_SUFFIX): DEFINES += -DNOINIT
|
2011-02-23 01:06:26 -08:00
|
|
|
test.$(OBJ_SUFFIX): CFLAGS := -O0
|
2011-06-15 21:28:59 -07:00
|
|
|
host_elf.$(OBJ_SUFFIX) host_elfhack.$(OBJ_SUFFIX): elfxx.h
|