public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Girish Joshi <girish946@gmail.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] manual: scripts/documented.sh updated
Date: Sun, 7 Apr 2024 13:43:02 +0530	[thread overview]
Message-ID: <CALkY8p-GpDo=410o2Z4u+_4wiWjDDrYJfDkb8Eg5Q4ZEOz=hKw@mail.gmail.com> (raw)
In-Reply-To: <CALkY8p8HnKFhkWnJuHtzmF-ZW_Oc_XUjnef40gskkuT4RVbsnA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 792 bytes --]

Hello Florian,
On Mon, Feb 27, 2023 at 11:26 PM Florian Weimer <fweimer@redhat.com> wrote:
> _IO_vfscanf should be recognized as an alias of vfscanf, but this is
> more of an RFE than a bug fix.

I was able to write a small python script that gets the list of
aliases in the given binaries and the html.
Not sure if this can be a separate script or should it be a part of
the same thing?
Please let me know if it can be a separate script, I'll post a patch for it.

Thanks!
Girish Joshi
girishjoshi.io

On Thu, Apr 4, 2024 at 7:28 PM Girish Joshi <girish946@gmail.com> wrote:
>
> On Wed, Apr 3, 2024 at 10:41 PM Adhemerval Zanella Netto
> <adhemerval.zanella@linaro.org> wrote:
> >
> > I will take a look.
> Thanks Adhemerval.
>
> Girish Joshi
> girishjoshi.io

[-- Attachment #2: aliases.py --]
[-- Type: text/x-python, Size: 3095 bytes --]

#!/bin/env python
import sys
import subprocess

# list of binaries to check for aliases
input_bins = [
    "libc.so",
    "math/libm.so",
    "rt/librt.so",
    "nptl/libpthread.so",
    "dlfcn/libdl.so",
    "login/libutil.so",
]
base_cmd = "readelf -Ws "

function_identifier = "FUNC"

base_html_body = """
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>glibc functions aliases</title>
  </head>

  <body>
    <center><h1>aliases <tt>glibc</tt> functions</h1></center>

    <center><p>The following table includes names of the function in glibc
    which are aliases of each other.  This list is
    automatically created and therefore might contain errors.</center>
"""


def get_aliases(bin, glibc_build_dir):
    """
    Get aliases of functions in the given binary.
    Aliases are functions that are mapped to the same address.

    Parameters:
        bin (str): binary to check for aliases
        glibc_build_dir (str): path to glibc build directory

    Returns:
        dict: dictionary of aliases.
    """

    # prepare the command string
    cmd = f"{base_cmd} {glibc_build_dir}/{bin}"

    # get the output of readelf
    output = subprocess.check_output(cmd, shell=True)
    lines = output.decode().split("\n")
    aliases = {}
    # parse the output to get the aliases
    for i in lines:
        details = [j for j in i.split(" ") if j]
        if len(details) > 7 and function_identifier in details[3]:
            if details[1] in aliases:
                aliases[details[1]].append(details[7])
            else:
                aliases[details[1]] = [details[7]]
    aliases = {i: aliases[i] for i in aliases if len(aliases[i]) > 1}
    return aliases


def generate_html(aliases, binary, html_body):
    """
    Generate html for the given aliases.

    Parameters:
        aliases (dict): dictionary of aliases
        binary (str): binary name
        html_body (str): html body

    Returns:
        str: html body
    """
    row = (
        """
    <br>
    <center><h1><b>Binary:</b> <tt>
    """
        + binary
        + """</tt><br></h1></center>
        <center><table  border="1 | 0" > 
            <td><tt>location</tt></td>
            <td><tt>funtions</tt></td>
    """
    )
    for i in aliases:
        row += f"    <tr><td>0x{i}</td>\n"
        row += "    <td>\n"
        for j in aliases[i]:
            row += f"        {j}<br>\n"
        row += "    </td>\n"
    row += "    </tr>\n    </table></center>\n"

    html_body = row
    return html_body


if __name__ == "__main__":
    if len(sys.argv) == 1:
        print("Usage: aliases.py <glibc-build-dir>")
        sys.exit(1)

    # remove trailing slash if present
    glib_build_dir = sys.argv[1].strip("/") 
    try:
        html_body = base_html_body
        for bin in input_bins:
            aliases = get_aliases(bin, glib_build_dir)
            html_body += generate_html(aliases, bin, html_body)
        html_body += "  </body>\n</html>"
        print(html_body)
    except subprocess.CalledProcessError as ex:
        print(f"error: {ex}")
        sys.exit(1)

  reply	other threads:[~2024-04-07  8:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 14:34 Girish Joshi
2023-02-27 17:56 ` Florian Weimer
2023-03-05  6:14   ` Girish Joshi
2023-03-05  6:55     ` Girish Joshi
2023-03-11 14:48     ` Joe Simmons-Talbott
2024-03-30 18:54       ` Girish Joshi
2024-04-01 16:33         ` Joe Talbott
2024-04-02  4:01           ` Girish Joshi
2024-04-03 15:44             ` Girish Joshi
2024-04-03 17:10               ` Adhemerval Zanella Netto
2024-04-04 13:58                 ` Girish Joshi
2024-04-07  8:13                   ` Girish Joshi [this message]
2024-04-10 18:35                 ` Girish Joshi
2024-04-11 17:18           ` Adhemerval Zanella Netto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALkY8p-GpDo=410o2Z4u+_4wiWjDDrYJfDkb8Eg5Q4ZEOz=hKw@mail.gmail.com' \
    --to=girish946@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).