xref: /aosp_15_r20/external/toolchain-utils/debug_info_test/check_ngcc.py (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1*760c253cSXin Li# -*- coding: utf-8 -*-
2*760c253cSXin Li# Copyright 2018 The ChromiumOS Authors
3*760c253cSXin Li# Use of this source code is governed by a BSD-style license that can be
4*760c253cSXin Li# found in the LICENSE file.
5*760c253cSXin Li
6*760c253cSXin Li"""Check whether the compile unit is not built by gcc."""
7*760c253cSXin Li
8*760c253cSXin Li
9*760c253cSXin Lifrom allowlist import is_allowlisted
10*760c253cSXin Li
11*760c253cSXin Li
12*760c253cSXin Lidef not_by_gcc(dso_path, producer, comp_path):
13*760c253cSXin Li    """Check whether the compile unit is not built by gcc.
14*760c253cSXin Li
15*760c253cSXin Li    Args:
16*760c253cSXin Li      dso_path: path to the elf/dso.
17*760c253cSXin Li      producer: DW_AT_producer contains the compiler command line.
18*760c253cSXin Li      comp_path: DW_AT_comp_dir + DW_AT_name.
19*760c253cSXin Li
20*760c253cSXin Li    Returns:
21*760c253cSXin Li      False if compiled by gcc otherwise True.
22*760c253cSXin Li    """
23*760c253cSXin Li    if is_allowlisted("ngcc_comp_path", comp_path):
24*760c253cSXin Li        return True
25*760c253cSXin Li
26*760c253cSXin Li    if is_allowlisted("ngcc_dso_path", dso_path):
27*760c253cSXin Li        return True
28*760c253cSXin Li
29*760c253cSXin Li    return "GNU C" not in producer
30