Skip to content

Commit 0ac9188

Browse files
authored
Make fuchsia-test-runner.py compatible with new JSON output from llvm-readelf
[A recent commit in LLVM](llvm/llvm-project@ab930ee) modified the JSON output of LLVM. The LLVM change renamed "Notes" to "NoteSections" and inserted a new "Notes" key nested under each "NoteSection". This change shores up exceptions around reading the JSON output of llvm-readelf and reads from "NoteSections" instead of the non-existent "Notes".
1 parent 17a19e6 commit 0ac9188

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/ci/docker/scripts/fuchsia-test-runner.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,28 @@ def build_id(self, binary):
193193
stderr=subprocess.STDOUT,
194194
)
195195
if process.returncode:
196-
self.env_logger.error(
197-
f"llvm-readelf failed for binary {binary} with output {process.stdout}"
198-
)
199-
raise Exception(f"Unreadable build-id for binary {binary}")
200-
data = json.loads(process.stdout)
201-
if len(data) != 1:
202-
raise Exception(f"Unreadable output from llvm-readelf for binary {binary}")
203-
notes = data[0]["Notes"]
204-
for note in notes:
205-
note_section = note["NoteSection"]
206-
if note_section["Name"] == ".note.gnu.build-id":
207-
return note_section["Note"]["Build ID"]
196+
e = f"llvm-readelf failed for binary {binary} with output {process.stdout}"
197+
self.env_logger.error(e)
198+
raise Exception(e)
199+
200+
elf_output = json.loads(process.stdout)
201+
if len(elf_output) != 1:
202+
raise Exception(f"JSON returned by llvm-readelf for binary {binary} is not a list with a single entry")
203+
204+
try:
205+
note_sections = getattr(elf_output[0], "NoteSections")
206+
except AttributeError as e:
207+
e.add_note(f'Failed to read "NoteSections" from llvm-readelf for binary {binary}')
208+
raise
209+
210+
for entry in note_sections:
211+
try:
212+
note_section = entry["NoteSection"]
213+
if note_section["Name"] == ".note.gnu.build-id":
214+
return note_section["Note"]["Build ID"]
215+
except AttributeError as e:
216+
e.add_note(f'Failed to read ".note.gnu.build-id" from NoteSections entry in llvm-readelf for binary {binary}')
217+
raise
208218
raise Exception(f"Build ID not found for binary {binary}")
209219

210220
def generate_buildid_dir(

0 commit comments

Comments
 (0)