From patchwork Sat Dec 21 10:16:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 37060 Received: (qmail 104353 invoked by alias); 21 Dec 2019 10:16:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 104340 invoked by uid 89); 21 Dec 2019 10:16:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576923392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LZb6fVCqt1eDyvfK692nXqQFfEmwuQ1YFcFzjxUbY/Y=; b=B3gtqx+pPzb26CwE9ao9mozZeHwwvvLoJYhakEdZWOFd0doc9qRoAwOdMGdPv9II4/5SO/ jOXU60YxFTy59H72q/puUevnyOvjreO5dJCYPpCLNaTDTbD/YDdPtQth+IiynIfLnlTrhC 3BJfnFish6PovsC7vLaMwNjjS1Mde9Y= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [RFC] [PATCH] Add scripts/run-tool.py Date: Sat, 21 Dec 2019 11:16:26 +0100 Message-ID: <87woaqvv9h.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 This is a wrapper script for the toolchain built by build-many-glibcs.py. It attempts to guess the right toolchain based on ELF properties, and runs that tool. I'd like to receive feedback if something like this is useful, and perhaps how to improve the MIPS selector (which is rather hackish at present). Thanks, Florian ----- scripts/run-tool.py | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) diff --git a/scripts/run-tool.py b/scripts/run-tool.py new file mode 100644 index 0000000000..64336ce8f1 --- /dev/null +++ b/scripts/run-tool.py @@ -0,0 +1,278 @@ +#!/usr/bin/python3 + +"""Run the appropriate tool from a build-many-glibcs.py compilers tree. + +Automatically pick the right tool path based on ELF input files. By +default, the first argument on the command line that can be opened as +an ELF file determines the architecture, but this can be overriden by +the --ref argument. + +""" + +import argparse +import os +import os.path +import struct +import sys + + +def is_elf(blob): + return blob[:4] == b'\177ELF' + + +class ElfHeader(object): + def __init__(self, blob): + if not is_elf(blob): + raise ValueError('Invalid ELF magic: {!r}'.format(blob[:4])) + self.blob = blob + + elfclass = blob[4] + if elfclass == 1: + self.wordsize = 32 + flags_offset = 36 + elif elfclass == 2: + self.wordsize = 64 + flags_offset = 48 + else: + raise ValueError('Invalid ELF class: {!r}'.format(elfclass)) + + endian = blob[5] + if endian == 1: + self.endian = 'little' + self.__uint16 = '