mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-30 10:12:59 +00:00
Bug 716295 part 6 - Create elfhack tests for both DT_INIT and DT_INIT_ARRAY. r=nfroyd
This commit is contained in:
parent
5c651e0b18
commit
89d385a324
@ -38,7 +38,8 @@ endif
|
||||
CSRCS := \
|
||||
inject/$(CPU).c \
|
||||
inject/$(CPU)-noinit.c \
|
||||
test.c \
|
||||
test-ctors.c \
|
||||
test-array.c \
|
||||
$(NULL)
|
||||
|
||||
ifndef CROSS_COMPILE
|
||||
@ -53,33 +54,39 @@ OS_CXXFLAGS := $(filter-out -pedantic,$(OS_CXXFLAGS))
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
test$(DLL_SUFFIX): test.$(OBJ_SUFFIX) elfhack $(CSRCS:.c=.$(OBJ_SUFFIX))
|
||||
$(MKSHLIB) $(LDFLAGS) $<
|
||||
test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX): %$(DLL_SUFFIX): %.$(OBJ_SUFFIX) elfhack $(filter inject/%,$(CSRCS:.c=.$(OBJ_SUFFIX)))
|
||||
$(MKSHLIB) $(LDFLAGS) $< -nostartfiles
|
||||
@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 ===
|
||||
# Fail if the library doesn't have $(DT_TYPE) .dynamic info
|
||||
$(TOOLCHAIN_PREFIX)readelf -d $@ | grep '($(DT_TYPE))'
|
||||
@rm -f $@.bak
|
||||
$(CURDIR)/elfhack -b -f $@
|
||||
# Fail if the backup file doesn't exist
|
||||
[ -f "$@.bak" ]
|
||||
# Fail if the new library doesn't contain less relocations
|
||||
[ $$(objdump -R $@.bak | wc -l) -gt $$(objdump -R $@ | wc -l) ]
|
||||
[ $$($(TOOLCHAIN_PREFIX)objdump -R $@.bak | wc -l) -gt $$(objdump -R $@ | wc -l) ]
|
||||
|
||||
.PRECIOUS: test$(DLL_SUFFIX)
|
||||
test-array$(DLL_SUFFIX): DT_TYPE=INIT_ARRAY
|
||||
test-ctors$(DLL_SUFFIX): DT_TYPE=INIT
|
||||
|
||||
GARBAGE += test$(DLL_SUFFIX) test$(DLL_SUFFIX).bak
|
||||
.PRECIOUS: test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX)
|
||||
|
||||
libs:: test$(DLL_SUFFIX)
|
||||
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)
|
||||
|
||||
ifndef CROSS_COMPILE
|
||||
dummy: dummy.$(OBJ_SUFFIX) test$(DLL_SUFFIX)
|
||||
dummy: dummy.$(OBJ_SUFFIX)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
libs:: dummy
|
||||
# Will either crash or return exit code 1 if elfhack is broken
|
||||
LD_LIBRARY_PATH=$(CURDIR) $(CURDIR)/dummy
|
||||
LD_PRELOAD=$(CURDIR)/test-array$(DLL_SUFFIX) $(CURDIR)/dummy
|
||||
LD_PRELOAD=$(CURDIR)/test-ctors$(DLL_SUFFIX) $(CURDIR)/dummy
|
||||
|
||||
GARBAGE += dummy
|
||||
endif
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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/. */
|
||||
|
||||
extern __attribute__((visibility("default"))) int print_status();
|
||||
extern __attribute__((visibility("default"), weak)) int print_status();
|
||||
|
||||
int main() {
|
||||
return print_status();
|
||||
|
8
build/unix/elfhack/test-array.c
Normal file
8
build/unix/elfhack/test-array.c
Normal file
@ -0,0 +1,8 @@
|
||||
/* 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/. */
|
||||
|
||||
#include "test.c"
|
||||
|
||||
__attribute__((section(".init_array"), used))
|
||||
static void (*init_array[])() = { end_test, test };
|
17
build/unix/elfhack/test-ctors.c
Normal file
17
build/unix/elfhack/test-ctors.c
Normal file
@ -0,0 +1,17 @@
|
||||
/* 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/. */
|
||||
|
||||
#include "test.c"
|
||||
|
||||
/* Recent binutils would put .ctors content into a .init_array section */
|
||||
__attribute__((section(".manual_ctors"), used))
|
||||
static void (*ctors[])() = { (void (*)())-1, end_test, test, NULL };
|
||||
|
||||
__attribute__((section(".init")))
|
||||
void _init() {
|
||||
void (**func)() = &ctors[sizeof(ctors) / sizeof(void (*)()) - 1];
|
||||
while (*(--func) != (void (*)())-1) {
|
||||
(*func)();
|
||||
}
|
||||
}
|
@ -125,14 +125,14 @@ int print_status() {
|
||||
* following sections as part of the PT_TLS segment. */
|
||||
__thread int foo[1024];
|
||||
|
||||
__attribute__((constructor)) void end_test() {
|
||||
void end_test() {
|
||||
static int count = 0;
|
||||
/* Only exit when both constructors have been called */
|
||||
if (++count == 2)
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
__attribute__((constructor)) void test() {
|
||||
void test() {
|
||||
int i = 0, j = 0;
|
||||
#define DEF_(a,i,w) \
|
||||
if (a[i++] != str_ ## w) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user