diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2012-05-01 14:59:54 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2012-05-01 14:59:54 -0700 |
commit | 096d6566c981b87f45bde21c2b648862c563f317 (patch) | |
tree | 32e28c5df6b677b63c5d346930fa33d34fb15f8f /scripts | |
parent | d6007fe4bdee44fe8c0f117fb0cb1b6f3feef00b (diff) | |
parent | f5a01ca927f9141606276b05ad87974593a608a1 (diff) | |
download | glibc-096d6566c981b87f45bde21c2b648862c563f317.tar.gz glibc-096d6566c981b87f45bde21c2b648862c563f317.tar.xz glibc-096d6566c981b87f45bde21c2b648862c563f317.zip |
Merge remote-tracking branch 'origin/master' into hjl/x32/master
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/check-execstack.awk | 52 | ||||
-rw-r--r-- | scripts/check-textrel.awk | 41 | ||||
-rw-r--r-- | scripts/localplt.awk | 59 |
3 files changed, 152 insertions, 0 deletions
diff --git a/scripts/check-execstack.awk b/scripts/check-execstack.awk new file mode 100644 index 0000000000..21d37e9f47 --- /dev/null +++ b/scripts/check-execstack.awk @@ -0,0 +1,52 @@ +# This awk script expects to get command-line files that are each +# the output of 'readelf -l' on a single shared object. +# But the first file should contain just "execstack-no" or "execstack-yes", +# indicating what the default is in the absence of PT_GNU_STACK. +# It exits successfully (0) if none indicated executable stack. +# It fails (1) if any did indicate executable stack. +# It fails (2) if the input did not take the expected form. + +BEGIN { result = sanity = 0; default_exec = -1 } + +/^execstack-no$/ { default_exec = 0; next } +/^execstack-yes$/ { default_exec = 1; next } + +function check_one(name) { + if (default_exec == -1) { + print "*** missing execstack-default file?"; + result = 2; + } + + if (!sanity) { + print name ": *** input did not look like readelf -l output"; + result = 2; + } else if (stack_line) { + if (stack_line ~ /^.*RW .*$/) { + print name ": OK"; + } else if (stack_line ~ /^.*E.*$/) { + print name ": *** executable stack signaled"; + result = result ? result : 1; + } + } else if (default_exec) { + print name ": *** no PT_GNU_STACK entry"; + result = result ? result : 1; + } else { + print name ": no PT_GNU_STACK but default is OK"; + } + + sanity = 0; +} + +FILENAME != lastfile { + if (lastfile) + check_one(lastfile); + lastfile = FILENAME; +} + +$1 == "Type" && $7 == "Flg" { sanity = 1; stack_line = "" } +$1 == "GNU_STACK" { stack_line = $0 } + +END { + check_one(lastfile); + exit(result); +} diff --git a/scripts/check-textrel.awk b/scripts/check-textrel.awk new file mode 100644 index 0000000000..e7f2d70084 --- /dev/null +++ b/scripts/check-textrel.awk @@ -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); +} diff --git a/scripts/localplt.awk b/scripts/localplt.awk new file mode 100644 index 0000000000..2265b026f0 --- /dev/null +++ b/scripts/localplt.awk @@ -0,0 +1,59 @@ +# This awk script expects to get command-line files that are each +# the output of 'readelf -WSdr' on a single shared object, and named +# .../NAME.jmprel where NAME is the unadorned file name of the shared object. +# It writes "NAME: SYMBOL" for each PLT entry in NAME that refers to a +# symbol defined in the same object. + +BEGIN { result = 0 } + +FILENAME != lastfile { + if (lastfile && jmprel_offset == 0) { + print FILENAME ": *** failed to find expected output (readelf -WSdr)"; + result = 2; + } + lastfile = FILENAME; + jmprel_offset = 0; + delete section_offset_by_address; +} + +/^Section Headers:/ { in_shdrs = 1; next } +in_shdrs && !/^ +\[/ { in_shdrs = 0 } + +in_shdrs && /^ +\[/ { sub(/\[ +/, "[") } +in_shdrs { + address = strtonum("0x" $4); + offset = strtonum("0x" $5); + section_offset_by_address[address] = offset; +} + +in_shdrs { next } + +$1 == "Offset" && $2 == "Info" { in_relocs = 1; next } +NF == 0 { in_relocs = 0 } + +in_relocs && relocs_offset == jmprel_offset && NF >= 5 { + symval = strtonum("0x" $4); + if (symval != 0) + print whatfile, $5 +} + +in_relocs { next } + +$1 == "Relocation" && $2 == "section" && $5 == "offset" { + relocs_offset = strtonum($6); + whatfile = gensub(/^.*\/([^/]+)\.jmprel$/, "\\1:", 1, FILENAME); + next +} + +$2 == "(JMPREL)" { + jmprel_addr = strtonum($3); + if (jmprel_addr in section_offset_by_address) { + jmprel_offset = section_offset_by_address[jmprel_addr]; + } else { + print FILENAME ": *** DT_JMPREL does not match any section's address"; + result = 2; + } + next +} + +END { exit(result) } |