From nobody Fri Apr 19 00:39:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=pass(p=reject dis=none) header.from=seabios.org ARC-Seal: i=1; a=rsa-sha256; t=1657679896; cv=none; d=zohomail.com; s=zohoarc; b=UTPAiWAVYbOUUdWsknunDanuWP3nUqa2TRqWjepqXMddAUoROCrYioKkFBBzGRvT+pEiwCRYIn2P22KTDUoDuUIOJDZQ5i4LWxdNQI5PRttD4tabJfbhwPF8UX3068sDg45k9aL/QmEmaxXX2Pe76a5uh4vR55Cs2uEeT5BfEZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657679896; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Subject:To; bh=Rv0KVlHzK7gbRLoiwgJOZemK7NEtTRUXhwAqQForbL4=; b=mkFyVhFmC5FKewEvOeiEsHKH3k29LA5NtDVcC389KuAjJ2jB1DIUKrx7RjcY1n99XiPlgzWNg59ktbjLozPY0h1R4uKWNH9R4C5xGlfeMjfeZ50x4g1Q6fWeiLZfZKr0YHNBqk20DswM22OMKEc9g3SZFRqNuDr/hV/0oSLf3Zs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1657679896474493.2769949157482; Tue, 12 Jul 2022 19:38:16 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id F211E222EF; Wed, 13 Jul 2022 02:38:10 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 673AA2D722 for ; Wed, 13 Jul 2022 02:37:51 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Tue, 12 Jul 2022 19:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seabios.org; s=dkim; t=1657679892; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:list-id:list-owner:list-unsubscribe:list-subscribe:list-post; bh=Rv0KVlHzK7gbRLoiwgJOZemK7NEtTRUXhwAqQForbL4=; b=8a5bJzNH8QOt5lcLJTNRa8Ggl7+Q/ujmK5B3wxZoc75LR/Smwy2zoeIZy2b4dBUrMweCpF fHxwisGaYBT64O+qBZf6JyZ1le+QmcL6G6zEIrVfKar3eTIcvmK0c8Sw+yCLK6haBcne/s VbpNTZNaKOCbYV/E56A+T631QWwlIuM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=LuRubJdQMNca9OdR69VlLkUPRWKL7EFMkEgIdt3Qkp8=; b=kN9F6zdRm0+00+mq6uBhSEcr11G2gRPvlvPXgRNUswRF535EEIp6Pe5enIzy8r4ut9 uhF5lZWxBKbUHz2bnpeCxsGmuLXcQhJmhM+/kCQYreQPjMYO7UOj+dyFm7JML9BWH4g8 meW18mPAT0WlCQStX0wAEOluAUCkjLtSEfvkSWbmFOa6KtihtP9kK04cAf79rYc+DAmZ 4Bpoq5hljNCUqBycEjd0xtxuogAl6UUPc96UmcG92LSrWhVojZ8icgfWICZndVNWqu6U Ynqza7ow9D0BXQbkjFj+DVC3d64ctfrzH9wvs+mkhynz1Fd6Xg1WCQATvHJ8VJDtMjUn hkTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=LuRubJdQMNca9OdR69VlLkUPRWKL7EFMkEgIdt3Qkp8=; b=mrI49BloloRytoq+ouImTdyC1LygF4auDpx79HJXvLCLus/j5ExdAntuG1xYLraNRi lHzvHc9DgAeGUGanvpIF2KE2WqiXLyGGzPf3z/33ZsumLiDgSwFHZ6fjktHaGlpaVmkB gFo5vT1j3KEgBXNB0+ibB5bjxqDFoOrXLSp7QmKlfZlPYKBfvjpU5e4++ntTWzANvWJI tIPmlggXs1/W4OfrLz1cfkOg55iuYRsmtIJnGGcqUI4vmr8t0y6StIX8eKANoMy2jHBz PqS/EBKpUjXFN/xf3MMzAlvBImYTA/Jknh8d60Ag/I8M/FeCtImkWnbX0HBqM3mTzf+D m9Mg== X-Gm-Message-State: AJIora94M2dZuuHHKU5eIde1ghQk+Z46pllAYxIw4EXAT8+1nOvXRL2J 6rfXa9HZDMI2Qa6WsuUrph5tcO0Kx86bMHgUQwpFidbqAjhivVSGsA47BWxt8ByPXZvtG9vslFM EVrmytpiyt8zecoanT3V/g/b2j1IktWYYipHM42EljWki3uV0ZWKOiJD4STIL X-Google-Smtp-Source: AGRyM1tR9HHN/GggBLBhQwycauo80QdIVY0b5QXPJ1ro28px8/DH37kO0nZW5af75Eff4734OlAdNJkSsP6y X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:2d73:f468:8288:85ec]) (user=maskray job=sendgmr) by 2002:a5b:ecc:0:b0:66e:da0a:7736 with SMTP id a12-20020a5b0ecc000000b0066eda0a7736mr1364912ybs.587.1657679870031; Tue, 12 Jul 2022 19:37:50 -0700 (PDT) Date: Tue, 12 Jul 2022 19:37:44 -0700 Message-Id: <20220713023744.3451795-1-maskray@google.com> Mime-Version: 1.0 To: seabios@seabios.org, Brad Smith Message-ID-Hash: RE3VHJYYNR5WPNIJJALOFGCYAS2DTHJH X-Message-ID-Hash: RE3VHJYYNR5WPNIJJALOFGCYAS2DTHJH X-MailFrom: 3_i_OYgcKB7MfTldkTrZhhZeX.VhflXTUbhllXTUbhl.hkZ@flex--maskray.bounces.google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Fangrui Song X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCH v3] Replace $(OBJDUMP) -thr with $(READELF) -WSrs List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Fangrui Song via SeaBIOS Reply-To: Fangrui Song Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: + X-Spam-Level: * Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: pass (identity @seabios.org) X-ZM-MESSAGEID: 1657679897100100001 Content-Type: text/plain; charset="utf-8" objdump -h relies heavily on BFD internals and the BFD flags. The output is difficult to emulate in llvm-objdump. (llvm-objdump -h has a different output https://reviews.llvm.org/D57146). Switch to READELF, so that llvm-readelf can be used as an alternative. readelf is generally better than objdump when dumping ELF section/symbol information. Signed-off-by: Fangrui Song --- Changes from v2 (https://mail.coreboot.org/hyperkitty/list/seabios@seabios.= org/message/4AZCP2KR63YAURID5FFXOWMPIOB4BNRJ/) * Change an objdump comment to mention readelf * For your convenience, this patch is available on https://github.com/MaskR= ay/seabios/tree/readelf --- Makefile | 18 +++--- scripts/checkrom.py | 2 +- scripts/layoutrom.py | 145 ++++++++++++++++++++----------------------- 3 files changed, 79 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index c108f87..5c6a838 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ endif AS=3D$(CROSS_PREFIX)as LD=3D$(CROSS_PREFIX)ld OBJCOPY=3D$(CROSS_PREFIX)objcopy -OBJDUMP=3D$(CROSS_PREFIX)objdump +READELF=3D$(CROSS_PREFIX)readelf STRIP=3D$(CROSS_PREFIX)strip PYTHON=3Dpython CPP=3Dcpp @@ -165,14 +165,14 @@ $(OUT)romlayout.o: src/romlayout.S $(OUT)autoconf.h $= (OUT)asm-offsets.h =20 $(OUT)romlayout16.lds: $(OUT)ccode32flat.o $(OUT)code32seg.o $(OUT)ccode16= .o $(OUT)romlayout.o src/version.c scripts/layoutrom.py scripts/buildversio= n.py @echo " Building ld scripts" - $(Q)$(PYTHON) ./scripts/buildversion.py -e "$(EXTRAVERSION)" -t "$(CC);$(= AS);$(LD);$(OBJCOPY);$(OBJDUMP);$(STRIP)" $(OUT)autoversion.h + $(Q)$(PYTHON) ./scripts/buildversion.py -e "$(EXTRAVERSION)" -t "$(CC);$(= AS);$(LD);$(OBJCOPY);$(READELF);$(STRIP)" $(OUT)autoversion.h $(Q)$(CC) $(CFLAGS32FLAT) -c src/version.c -o $(OUT)version.o $(Q)$(LD) $(LD32BIT_FLAG) -r $(OUT)ccode32flat.o $(OUT)version.o -o $(OUT= )code32flat.o $(Q)$(LD) $(LD32BIT_FLAG) -r $(OUT)ccode16.o $(OUT)romlayout.o -o $(OUT)c= ode16.o - $(Q)$(OBJDUMP) -thr $(OUT)code32flat.o > $(OUT)code32flat.o.objdump - $(Q)$(OBJDUMP) -thr $(OUT)code32seg.o > $(OUT)code32seg.o.objdump - $(Q)$(OBJDUMP) -thr $(OUT)code16.o > $(OUT)code16.o.objdump - $(Q)$(PYTHON) ./scripts/layoutrom.py $(OUT)code16.o.objdump $(OUT)code32s= eg.o.objdump $(OUT)code32flat.o.objdump $(OUT)$(KCONFIG_AUTOHEADER) $(OUT)r= omlayout16.lds $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds + $(Q)$(READELF) -WSrs $(OUT)code32flat.o > $(OUT)code32flat.o.readelf + $(Q)$(READELF) -WSrs $(OUT)code32seg.o > $(OUT)code32seg.o.readelf + $(Q)$(READELF) -WSrs $(OUT)code16.o > $(OUT)code16.o.readelf + $(Q)$(PYTHON) ./scripts/layoutrom.py $(OUT)code16.o.readelf $(OUT)code32s= eg.o.readelf $(OUT)code32flat.o.readelf $(OUT)$(KCONFIG_AUTOHEADER) $(OUT)r= omlayout16.lds $(OUT)romlayout32seg.lds $(OUT)romlayout32flat.lds =20 # These are actually built by scripts/layoutrom.py above, but by pulling t= hem # into an extra rule we prevent make -j from spawning layoutrom.py 4 times. @@ -193,9 +193,9 @@ $(OUT)rom.o: $(OUT)rom16.noexec.o $(OUT)rom32seg.noexec= .o $(OUT)code32flat.o $(O $(OUT)bios.bin.prep: $(OUT)rom.o scripts/checkrom.py @echo " Prepping $@" $(Q)rm -f $(OUT)bios.bin $(OUT)Csm16.bin $(OUT)bios.bin.elf - $(Q)$(OBJDUMP) -thr $< > $<.objdump + $(Q)$(READELF) -WSrs $< > $<.readelf $(Q)$(OBJCOPY) -O binary $< $(OUT)bios.bin.raw - $(Q)$(PYTHON) ./scripts/checkrom.py $<.objdump $(CONFIG_ROM_SIZE) $(OUT)b= ios.bin.raw $(OUT)bios.bin.prep + $(Q)$(PYTHON) ./scripts/checkrom.py $<.readelf $(CONFIG_ROM_SIZE) $(OUT)b= ios.bin.raw $(OUT)bios.bin.prep =20 $(OUT)bios.bin: $(OUT)bios.bin.prep @echo " Creating $@" @@ -237,7 +237,7 @@ $(OUT)vgaentry.o: vgasrc/vgaentry.S $(OUT)autoconf.h $(= OUT)asm-offsets.h =20 $(OUT)vgarom.o: $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgasrc/vgalayout= .lds vgasrc/vgaversion.c scripts/buildversion.py @echo " Linking $@" - $(Q)$(PYTHON) ./scripts/buildversion.py -e "$(EXTRAVERSION)" -t "$(CC);$(= AS);$(LD);$(OBJCOPY);$(OBJDUMP);$(STRIP)" $(OUT)autovgaversion.h + $(Q)$(PYTHON) ./scripts/buildversion.py -e "$(EXTRAVERSION)" -t "$(CC);$(= AS);$(LD);$(OBJCOPY);$(READELF);$(STRIP)" $(OUT)autovgaversion.h $(Q)$(CC) $(CFLAGS16) -c vgasrc/vgaversion.c -o $(OUT)vgaversion.o $(Q)$(LD) --gc-sections -T $(OUT)vgasrc/vgalayout.lds $(OUT)vgaccode16.o = $(OUT)vgaentry.o $(OUT)vgaversion.o -o $@ =20 diff --git a/scripts/checkrom.py b/scripts/checkrom.py index a5b15a4..4a23f0a 100755 --- a/scripts/checkrom.py +++ b/scripts/checkrom.py @@ -21,7 +21,7 @@ def main(): =20 # Read in symbols objinfofile =3D open(objinfo, 'r') - symbols =3D layoutrom.parseObjDump(objinfofile, 'in')[1] + symbols =3D layoutrom.parseReadElf(objinfofile, 'in')[1] =20 # Read in raw file f =3D open(rawfile, 'rb') diff --git a/scripts/layoutrom.py b/scripts/layoutrom.py index 7bc4a57..f4b94ea 100755 --- a/scripts/layoutrom.py +++ b/scripts/layoutrom.py @@ -541,87 +541,80 @@ class Reloc: class Symbol: name =3D offset =3D section =3D None =20 -# Read in output from objdump -def parseObjDump(file, fileid): +def parseReadElf(file, fileid): # sections =3D [section, ...] sections =3D [] sectionmap =3D {} # symbols[symbolname] =3D symbol symbols =3D {} + lines =3D file.readlines() =20 - state =3D None - for line in file.readlines(): - line =3D line.rstrip() - if line =3D=3D 'Sections:': - state =3D 'section' - continue - if line =3D=3D 'SYMBOL TABLE:': - state =3D 'symbol' - continue - if line.startswith('RELOCATION RECORDS FOR ['): - sectionname =3D line[24:-2] - if sectionname.startswith('.debug_'): - # Skip debugging sections (to reduce parsing time) - state =3D None - continue - state =3D 'reloc' - relocsection =3D sectionmap[sectionname] - continue + i =3D 0 + while not lines[i].startswith('Section Headers'): + i +=3D 1 + i +=3D 3 # Skip [Nr] and [ 0] + while ']' in lines[i]: + parts =3D lines[i][lines[i].find(']')+1:].split() + if len(parts) =3D=3D 10: + name, _, _, _, size, _, _, _, _, align =3D parts + else: # not SHF_ALLOC + name, _, _, _, size, _, _, _, align =3D parts + section =3D Section() + section.name =3D name + section.size =3D int(size, 16) + section.align =3D int(align) + section.fileid =3D fileid + section.relocs =3D [] + sections.append(section) + sectionmap[name] =3D section + i +=3D 1 =20 - if state =3D=3D 'section': - try: - idx, name, size, vma, lma, fileoff, align =3D line.split() - if align[:3] !=3D '2**': - continue - section =3D Section() - section.name =3D name - section.size =3D int(size, 16) - section.align =3D 2**int(align[3:]) - section.fileid =3D fileid - section.relocs =3D [] - sections.append(section) - sectionmap[name] =3D section - except ValueError: - pass + while not lines[i].startswith('Symbol table '): + i +=3D 1 + i +=3D 3 # Skip Num: and 0: + while i < len(lines) and ':' in lines[i]: + colon =3D lines[i].find(':') + parts =3D lines[i].split() + try: + ndx =3D int(parts[6]) + name =3D sections[ndx-1].name + except ValueError: # ABS or UND + ndx =3D 0 + name =3D '' + if parts[3] !=3D 'SECTION': + name =3D parts[7] + symbol =3D Symbol() + symbol.size =3D int(parts[2]) + symbol.offset =3D int(parts[1], 16) + symbol.name =3D name + symbol.section =3D sections[ndx-1] if ndx > 0 else None + symbols[name] =3D symbol + i +=3D 1 + + i =3D 0 + while i < len(lines): + if not lines[i].startswith('Relocation section'): + i +=3D 1 continue - if state =3D=3D 'symbol': - try: - parts =3D line[17:].split() - if len(parts) =3D=3D 3: - sectionname, size, name =3D parts - elif len(parts) =3D=3D 4 and parts[2] =3D=3D '.hidden': - sectionname, size, hidden, name =3D parts - else: - continue - symbol =3D Symbol() - symbol.size =3D int(size, 16) - symbol.offset =3D int(line[:8], 16) - symbol.name =3D name - symbol.section =3D sectionmap.get(sectionname) - symbols[name] =3D symbol - except ValueError: - pass + rel_name =3D lines[i][20:lines[i].index("'", 20)] + i +=3D 2 + if rel_name.startswith('.rel.debug_'): + # Skip debugging sections (to reduce parsing time) continue - if state =3D=3D 'reloc': - try: - off, type, symbolname =3D line.split() - reloc =3D Reloc() - reloc.offset =3D int(off, 16) - reloc.type =3D type - reloc.symbolname =3D symbolname - reloc.symbol =3D symbols.get(symbolname) - if reloc.symbol is None: - # Some binutils (2.20.1) give section name instead - # of a symbol - create a dummy symbol. - reloc.symbol =3D symbol =3D Symbol() - symbol.size =3D 0 - symbol.offset =3D 0 - symbol.name =3D symbolname - symbol.section =3D sectionmap.get(symbolname) - symbols[symbolname] =3D symbol - relocsection.relocs.append(reloc) - except ValueError: - pass + assert rel_name.startswith('.rel') + relocated =3D sectionmap[rel_name[4:]] + while lines[i][0].isalnum(): + line =3D lines[i] + off, _, typ, _, symbolname =3D line.split() + reloc =3D Reloc() + reloc.offset =3D int(off, 16) + reloc.type =3D typ + reloc.symbolname =3D symbolname + reloc.symbol =3D symbols.get(symbolname) + assert reloc.symbol is not None + relocated.relocs.append(reloc) + i +=3D 1 + return sections, symbols =20 # Parser for constants in simple C header files. @@ -644,15 +637,15 @@ def main(): # Get output name in16, in32seg, in32flat, cfgfile, out16, out32seg, out32flat =3D sys.a= rgv[1:] =20 - # Read in the objdump information + # Read in the readelf information infile16 =3D open(in16, 'r') infile32seg =3D open(in32seg, 'r') infile32flat =3D open(in32flat, 'r') =20 # infoX =3D (sections, symbols) - info16 =3D parseObjDump(infile16, '16') - info32seg =3D parseObjDump(infile32seg, '32seg') - info32flat =3D parseObjDump(infile32flat, '32flat') + info16 =3D parseReadElf(infile16, '16') + info32seg =3D parseReadElf(infile32seg, '32seg') + info32flat =3D parseReadElf(infile32flat, '32flat') =20 # Read kconfig config file config =3D scanconfig(cfgfile) --=20 2.37.0.144.g8ac04bfd2-goog _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org