This is an archive of the discontinued LLVM Phabricator instance.

[runtimes] Refactor Symbol Checking Tool
Needs ReviewPublic

Authored by francii on May 16 2023, 9:58 AM.

Details

Reviewers
ldionne
daltenty
Group Reviewers
Restricted Project
Restricted Project
Restricted Project
Summary

Refactor the symbol checking tools, making them more generic and using llvm-ifs to check the symbols instead of manual tooling.

Diff Detail

Event Timeline

francii created this revision.May 16 2023, 9:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 9:58 AM
francii requested review of this revision.May 16 2023, 9:58 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptMay 16 2023, 9:58 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript

@ldionne This is a prototype for a complete refactor of the symbol checker. There's a lot I don't know about other platforms and what we should expect to support, so please share your thoughts.

francii added inline comments.May 16 2023, 10:04 AM
runtimes/utils/sym_check/extract.py
10

magic and yaml are external modules. While we can likely get away without magic, since llvm-ifs requires us to output to a YAML file, I think it's best to read said file with yaml.safe_load()

francii edited the summary of this revision. (Show Details)
francii updated this revision to Diff 522720.May 16 2023, 11:17 AM

Small cleanup

This comment was removed by francii.
This comment was removed by francii.
francii updated this revision to Diff 522744.May 16 2023, 12:38 PM

Cleanup scripts, fixed circular import

francii updated this revision to Diff 522745.May 16 2023, 12:41 PM

Fix count used for removed and changed symbols

francii updated this revision to Diff 522751.May 16 2023, 1:01 PM

Add args.removed_only

francii added a comment.EditedMay 16 2023, 1:33 PM

Using a simple C file:

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Compiled with: clang testfile.c -shared -fPIC -o testlib.so

generate_abi_list.py will output the following JSON (whether to stdout or a file):

[
    {
        "Name": "_ITM_deregisterTMCloneTable",
        "Type": "NoType",
        "Undefined": true,
        "Weak": true
    },
    {
        "Name": "_ITM_registerTMCloneTable",
        "Type": "NoType",
        "Undefined": true,
        "Weak": true
    },
    {
        "Name": "__cxa_finalize",
        "Type": "Func",
        "Undefined": true,
        "Weak": true
    },
    {
        "Name": "__gmon_start__",
        "Type": "NoType",
        "Undefined": true,
        "Weak": true
    },
    {
        "Name": "main",
        "Type": "Func"
    },
    {
        "Name": "printf",
        "Type": "Func",
        "Undefined": true
    }
]

Saving this output to a file (sample.json) and giving both the file and the library to get_sym_diff.py outputs:

Symbols unchanged

In sample.json, I changed the name of the first symbol to Test_ITM_deregisterTMCloneTable and changed the visibility of the second symbol from "Weak": true to "Weak: false". I passed the original library and this altered symbol table to get_sym_diff.py as so:
python3 get_sym_diff.py testlib.so sample.json
The output is below:

Symbols Added: 1
Added {'Name': 'Test_ITM_deregisterTMCloneTable', 'Type': 'NoType', 'Undefined': True, 'Weak': True}
Symbols Removed: 1
Removed {'Name': '_ITM_deregisterTMCloneTable', 'Type': 'NoType', 'Undefined': True, 'Weak': True}
Symbols Changed: 1
_ITM_registerTMCloneTable: {'Name': '_ITM_registerTMCloneTable', 'Type': 'NoType', 'Undefined': True, 'Weak': True} -> {'Name': '_ITM_registerTMCloneTable', 'Type': 'NoType', 'Undefined': True, 'Weak': False}
ABI BREAKAGE!: 1 added, 1 removed, 1 changed.
francii updated this revision to Diff 522831.May 16 2023, 4:49 PM

Consolidate similar logic found in utils and extract

francii updated this revision to Diff 527703.Jun 1 2023, 7:17 PM

Rebase and update __init__.py

francii updated this revision to Diff 528292.Jun 4 2023, 11:05 PM

Rebase and update logic

francii updated this revision to Diff 530965.Jun 13 2023, 10:12 AM

Rebase and cleanup

francii updated this revision to Diff 530972.Jun 13 2023, 10:24 AM

Fix diff.py

@ldionne re-pinging for review.

francii updated this revision to Diff 544449.Jul 26 2023, 11:16 AM

Formatting

@daltenty pinging for review

francii updated this revision to Diff 544460.Jul 26 2023, 11:42 AM

Improve readability of report_diff()