5
Last change
on this file since 31e22e3 was
31e22e3,
checked in by Chris Johns <chrisj@…>, on 01/08/17 at 22:05:18
|
libelf: Use minimal environment for C translation with readelf.
The output of readelf needs to be in English.
|
-
Property mode set to
100755
|
File size:
1.1 KB
|
Rev | Line | |
---|
[ec24a37] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
| 3 | # $Id: native-elf-format 2064 2011-10-26 15:12:32Z jkoshy $ |
---|
| 4 | # |
---|
| 5 | # Find the native ELF format for a host platform by compiling a |
---|
| 6 | # test object and examining the resulting object. |
---|
| 7 | # |
---|
| 8 | # This script is used if there is no easy way to determine this |
---|
| 9 | # information statically at compile time. |
---|
| 10 | |
---|
| 11 | program=`basename $0` |
---|
| 12 | tmp_c=`mktemp -u nefXXXXXX`.c |
---|
| 13 | tmp_o=`echo ${tmp_c} | sed -e 's/.c$/.o/'` |
---|
| 14 | |
---|
| 15 | trap "rm -f ${tmp_c} ${tmp_o}" 0 1 2 3 15 |
---|
| 16 | |
---|
| 17 | touch ${tmp_c} |
---|
| 18 | |
---|
| 19 | echo "/* Generated by ${program} on `date` */" |
---|
| 20 | |
---|
| 21 | cc -c ${tmp_c} -o ${tmp_o} |
---|
[31e22e3] | 22 | LANG="C" readelf -h ${tmp_o} | awk ' |
---|
[ec24a37] | 23 | $1 ~ "Class:" { |
---|
| 24 | sub("ELF","",$2); elfclass = $2; |
---|
| 25 | } |
---|
| 26 | $1 ~ "Data:" { |
---|
| 27 | if (match($0, "little")) { |
---|
| 28 | elfdata = "LSB"; |
---|
| 29 | } else { |
---|
| 30 | elfdata = "MSB"; |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | $1 ~ "Machine:" { |
---|
| 34 | if (match($0, "Intel.*386")) { |
---|
| 35 | elfarch = "EM_386"; |
---|
| 36 | } else if (match($0, ".*X86-64")) { |
---|
| 37 | elfarch = "EM_X86_64"; |
---|
| 38 | } else { |
---|
| 39 | elfarch = "unknown"; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | END { |
---|
| 43 | printf("#define ELFTC_CLASS ELFCLASS%s\n", elfclass); |
---|
| 44 | printf("#define ELFTC_ARCH %s\n", elfarch); |
---|
| 45 | printf("#define ELFTC_BYTEORDER ELFDATA2%s\n", elfdata); |
---|
| 46 | }' |
---|
Note: See
TracBrowser
for help on using the repository browser.