// find the one we are looking for. This format is slightly documented in "ELF
// for the ARM Architecture" but mostly this is derived from reading the source
// to gold and readelf.
-func parseArmAttributes(e binary.ByteOrder, initEhdrFlags uint32, data []byte) (ehdrFlags uint32, err error) {
- // We assume the soft-float ABI unless we see a tag indicating otherwise.
- if initEhdrFlags == 0x5000002 {
- ehdrFlags = 0x5000202
- }
+func parseArmAttributes(e binary.ByteOrder, data []byte) (found bool, ehdrFlags uint32, err error) {
+ found = false
if data[0] != 'A' {
- return 0, fmt.Errorf(".ARM.attributes has unexpected format %c\n", data[0])
+ return false, 0, fmt.Errorf(".ARM.attributes has unexpected format %c\n", data[0])
}
data = data[1:]
for len(data) != 0 {
nulIndex := bytes.IndexByte(sectiondata, 0)
if nulIndex < 0 {
- return 0, fmt.Errorf("corrupt .ARM.attributes (section name not NUL-terminated)\n")
+ return false, 0, fmt.Errorf("corrupt .ARM.attributes (section name not NUL-terminated)\n")
}
name := string(sectiondata[:nulIndex])
sectiondata = sectiondata[nulIndex+1:]
for !attrList.done() {
attr := attrList.armAttr()
if attr.tag == TagABIVFPArgs && attr.ival == 1 {
+ found = true
ehdrFlags = 0x5000402 // has entry point, Version5 EABI, hard-float ABI
}
}
if attrList.err != nil {
- return 0, fmt.Errorf("could not parse .ARM.attributes\n")
+ return false, 0, fmt.Errorf("could not parse .ARM.attributes\n")
}
}
}
- return ehdrFlags, nil
+ return found, ehdrFlags, nil
}
// Load loads the ELF file pn from f.
if err := elfmap(elfobj, sect); err != nil {
return errorf("%s: malformed elf file: %v", pn, err)
}
- ehdrFlags, err = parseArmAttributes(e, initEhdrFlags, sect.base[:sect.size])
+ // We assume the soft-float ABI unless we see a tag indicating otherwise.
+ if initEhdrFlags == 0x5000002 {
+ ehdrFlags = 0x5000202
+ } else {
+ ehdrFlags = initEhdrFlags
+ }
+ found, newEhdrFlags, err := parseArmAttributes(e, sect.base[:sect.size])
if err != nil {
// TODO(dfc) should this return an error?
log.Printf("%s: %v", pn, err)
}
+ if found {
+ ehdrFlags = newEhdrFlags
+ }
}
if (sect.type_ != ElfSectProgbits && sect.type_ != ElfSectNobits) || sect.flags&ElfSectFlagAlloc == 0 {
continue