Skip to content

Commit

Permalink
Do check-textrel test using readelf rather than a build-time C program.
Browse files Browse the repository at this point in the history
  • Loading branch information
frobtech committed May 1, 2012
1 parent 615605c commit 82a79e7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 209 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2012-05-01 Roland McGrath <[email protected]>

* scripts/check-textrel.awk: New file.
* elf/Makefile ($(objpfx)check-textrel): Target removed.
(check-textrel-CFLAGS): Variable removed.
(all-built-dso): Use := to define.o
($(all-built-dso:=.dyn)): New static pattern rule.
(generated): Add those targets.
($(objpfx)check-textrel.out): Use the script on the .dyn files.
* config.make.in (READELF): New substituted variable.
* elf/check-textrel.c: File removed.

2012-05-01 Joseph Myers <[email protected]>

* conform/data/assert.h-data [ISO || ISO99 || ISO11] (*_t): Do not
Expand Down
1 change: 1 addition & 0 deletions config.make.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ BISON = @BISON@
AUTOCONF = @AUTOCONF@
OBJDUMP = @OBJDUMP@
OBJCOPY = @OBJCOPY@
READELF = @READELF@

# Installation tools.
INSTALL = @INSTALL@
Expand Down
27 changes: 16 additions & 11 deletions elf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,6 @@ CFLAGS-tst-pie1.c += $(pie-ccflag)

$(objpfx)tst-pie1: $(objpfx)tst-piemod1.so

check-textrel-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
$(objpfx)check-textrel: check-textrel.c
$(native-compile)

check-execstack-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -std=gnu99 \
$(objpfx:%/=-I%)
$(objpfx)check-execstack: check-execstack.c $(objpfx)check-execstack.h
Expand All @@ -895,14 +891,23 @@ $(objpfx)check-localplt: check-localplt.c
ifeq (yes,$(build-shared))
tests: $(objpfx)check-textrel.out $(objpfx)check-execstack.out

all-built-dso = $(common-objpfx)libc.so \
$(filter-out $(common-objpfx)linkobj/libc.so, \
$(sort $(wildcard $(common-objpfx)*/lib*.so \
$(common-objpfx)iconvdata/*.so)))
all-built-dso := $(common-objpfx)libc.so \
$(filter-out $(common-objpfx)linkobj/libc.so, \
$(sort $(wildcard $(addprefix $(common-objpfx), \
*/lib*.so \
iconvdata/*.so))))

$(objpfx)check-textrel.out: $(objpfx)check-textrel $(all-built-dso)
$(dir $<)$(notdir $<) $(filter-out $<, $^) > $@
generated += check-textrel check-textrel.out
$(all-built-dso:=.dyn): %.dyn: %
@rm -f $@T
LC_ALL=C $(READELF) -W -d $< > $@T
test -s $@T
mv -f $@T $@
generated += $(all-built-dso:=.dyn)

$(objpfx)check-textrel.out: $(..)scripts/check-textrel.awk \
$(all-built-dso:=.dyn)
LC_ALL=C $(AWK) -f $^ > $@
generated += check-textrel.out

$(objpfx)check-execstack.out: $(objpfx)check-execstack $(all-built-dso)
$(dir $<)$(notdir $<) $(filter-out $<, $^) > $@
Expand Down
198 changes: 0 additions & 198 deletions elf/check-textrel.c

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/check-textrel.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This awk script expects to get command-line files that are each
# the output of 'readelf -d' on a single shared object.
# It exits successfully (0) if none contained any TEXTREL markers.
# It fails (1) if any did contain a TEXTREL marker.
# It fails (2) if the input did not take the expected form.

BEGIN { result = textrel = sanity = 0 }

function check_one(name) {
if (!sanity) {
print name ": *** input did not look like readelf -d output";
result = 2;
} else if (textrel) {
print name ": *** text relocations used";
result = result ? result : 1;
} else {
print name ": OK";
}

textrel = sanity = 0;
}

FILENAME != lastfile {
if (lastfile)
check_one(lastfile);
lastfile = FILENAME;
}

$1 == "Tag" && $2 == "Type" { sanity = 1 }
$2 == "(TEXTREL)" { textrel = 1 }
$2 == "(FLAGS)" {
for (i = 3; i <= NF; ++i) {
if ($i == "TEXTREL")
textrel = 1;
}
}

END {
check_one(lastfile);
exit(result);
}

0 comments on commit 82a79e7

Please sign in to comment.