From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 568553951884 for ; Sun, 9 May 2021 21:42:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 568553951884 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-134-RUWWP4weOLO4zF3aHoiIDw-1; Sun, 09 May 2021 17:42:30 -0400 X-MC-Unique: RUWWP4weOLO4zF3aHoiIDw-1 Received: by mail-qv1-f70.google.com with SMTP id l19-20020a0ce5130000b02901b6795e3304so11029411qvm.2 for ; Sun, 09 May 2021 14:42:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=L4MQPc8IhJmMGVkd9Mp9DoeJyQbnDs8jFOPjz5C7DGw=; b=Uu0xuyzsdhIw3XgLiDeR1oIvvrps7hI9fdTmNxU1yWVObCqAZwYmudS2iogwpSJoUO wzX5obJSL1rU03EkdwDdQUQPF5Re2UADtFK+9ICk+43OVIQX7ZaHvxkOfiQiJIRnW8aS Ir694dohagNufkwLsi/xn+uhlFFU51dTOoU0gWnM4NL1gOFBBBmXvaPpwNz6S4dW6y8E 4wmWZ1groJS5+eKqXrIGy9pbc/VeSw07TMop8wfiUL26uzX/xsrMoANhRp5tdgqBDOup VAiP3yKX5+16z4E/HX9U05ACh4r426aT+rr5Ws0Md2WhpBLEp5rC9vFpL08QbQeSvY1g U7ZQ== X-Gm-Message-State: AOAM533MZHBW6e+yBI/cQDgfDb2cEbXxfCCRA14xeRzQAF7Dl2ZQT8I3 MN5A+wFlLpVrDpKWbZVimDUbNK9OrOgiLInKqSDeFdjJBImqIHmdhfyVT8yNOvTc94Tqv9g35lv S4jB6iwyyrKMk7QnwlaCNxQKf+T6L4NsrYC5LRSbpP1kuiNUFumCWlG3eQBB0szrMfb9gKw== X-Received: by 2002:a05:622a:18a:: with SMTP id s10mr19679019qtw.237.1620596549811; Sun, 09 May 2021 14:42:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJpriGPOEqjZHQkEBkJ54TwKI30WjBGA+jFHlocv2xFpGYpZPbAXsVYcmNxFJkcodVB9axkw== X-Received: by 2002:a05:622a:18a:: with SMTP id s10mr19679011qtw.237.1620596549582; Sun, 09 May 2021 14:42:29 -0700 (PDT) Received: from [192.168.1.16] (198-84-214-74.cpe.teksavvy.com. [198.84.214.74]) by smtp.gmail.com with ESMTPSA id x28sm1924428qtm.71.2021.05.09.14.42.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 May 2021 14:42:29 -0700 (PDT) Subject: Re: [PATCH 01/13] scripts/versions.awk: Add strings and hashes to To: Florian Weimer , libc-alpha@sourceware.org References: <3231520c8ff708bf771984715a02fd767f1c501e.1620323953.git.fweimer@redhat.com> From: Carlos O'Donell Organization: Red Hat Message-ID: Date: Sun, 9 May 2021 17:42:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <3231520c8ff708bf771984715a02fd767f1c501e.1620323953.git.fweimer@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 May 2021 21:42:34 -0000 On 5/6/21 2:08 PM, Florian Weimer via Libc-alpha wrote: > This generates new macros of this from: > > #define FIRST_VERSION_libc___pthread_mutex_lock_STRING "GLIBC_2.2.5" > #define FIRST_VERSION_libc___pthread_mutex_lock_HASH 0x9691a75 > > They are useful for symbol lookups using _dl_lookup_direct. Straight forward, makes sense, used in the next patch. Tested on x86_64 and i686 without regression. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell > --- > scripts/versions.awk | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/scripts/versions.awk b/scripts/versions.awk > index d56f4e712c..3291123666 100644 > --- a/scripts/versions.awk > +++ b/scripts/versions.awk > @@ -32,6 +32,29 @@ BEGIN { > sort = "sort -t. -k 1,1 -k 2n,2n -k 3 > " tmpfile; > } > > +# GNU awk does not implement the ord and chr functions. > +# > +# says that they are "written very nicely", using code similar to what > +# is included here. > +function chr(c) { > + return sprintf("%c", c) > +} > + > +BEGIN { > + for (c = 1; c < 127; c++) { > + ord_table[chr(c)] = c; > + } > +} > + > +function ord(c) { > + if (ord_table[c]) { > + return ord_table[c]; > + } else { > + printf("Invalid character reference: '%c'\n", c) > "/dev/stderr"; > + ++lossage; > + } > +} > + > # Remove comment lines. > /^ *#/ { > next; > @@ -90,6 +113,17 @@ function close_and_move(name, real_name) { > system(move_if_change " " name " " real_name " >&2"); > } > > +# ELF hash, for use with symbol versions. > +function elf_hash(s, i, acc) { > + acc = 0; > + for (i = 1; i <= length(s); ++i) { > + acc = and(lshift(acc, 4) + ord(substr(s, i, 1)), 0xffffffff); > + top = and(acc, 0xf0000000); > + acc = and(xor(acc, rshift(top, 24)), compl(top)); > + } > + return acc; > +} > + > # Now print the accumulated information. > END { > close(sort); > @@ -145,6 +179,8 @@ END { > && oldver ~ "^GLIBC_[0-9]" \ > && sym ~ "^[A-Za-z0-9_]*$") { > ver_val = oldver; > + printf("#define %s_STRING \"%s\"\n", first_ver_macro, ver_val) > first_ver_header; > + printf("#define %s_HASH 0x%x\n", first_ver_macro, elf_hash(ver_val)) > first_ver_header; > gsub("\\.", "_", ver_val); > printf("#define %s %s\n", first_ver_macro, ver_val) > first_ver_header; > first_ver_seen[first_ver_macro] = 1; > -- Cheers, Carlos.