kpatch/kpatch-build/gcc-plugins/ppc64le-plugin.c
Joe Lawrence 13182e50b0 gcc-plugin: update headers for gcc-12
Fix build error seen on gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1):

  g++ -MMD -MP -I../kmod/patch -Iinsn -Wall -Wsign-compare -Wno-sign-conversion -g -Werror -shared -I/usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include -Igcc-plugins -fPIC -fno-rtti -O2 -Wall gcc-plugins/ppc64le-plugin.c -o gcc-plugins/ppc64le-plugin.so
  In file included from /usr/include/features.h:490,
                   from /usr/include/bits/libc-header-start.h:33,
                   from /usr/include/stdio.h:27,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/system.h:46,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/gcc-plugin.h:28,
                   from gcc-plugins/gcc-common.h:6,
                   from gcc-plugins/ppc64le-plugin.c:1:
  /usr/include/bits/error-ldbl.h:23:1: error: type of ‘error’ is unknown
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  /usr/include/bits/error-ldbl.h:23:1: error: ‘int error’ redeclared as different kind of entity
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  In file included from gcc-plugins/ppc64le-plugin.c:2:
  /usr/include/error.h:31:13: note: previous declaration ‘void error(int, int, const char*, ...)’
     31 | extern void error (int __status, int __errnum, const char *__format, ...)
        |             ^~~~~
  make[1]: *** [Makefile:39: gcc-plugins/ppc64le-plugin.so] Error 1

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-27 16:41:48 -04:00

98 lines
2.6 KiB
C

#include <error.h>
#include "gcc-common.h"
#define PLUGIN_NAME "ppc64le-plugin"
#if BUILDING_GCC_VERSION < 10000
#define CALL_LOCAL "*call_local_aixdi"
#define CALL_NONLOCAL "*call_nonlocal_aixdi"
#define CALL_VALUE_LOCAL "*call_value_local_aixdi"
#define CALL_VALUE_NONLOCAL "*call_value_nonlocal_aixdi"
#else
#define CALL_LOCAL "*call_localdi"
#define CALL_NONLOCAL "*call_nonlocal_aixdi"
#define CALL_VALUE_LOCAL "*call_value_localdi"
#define CALL_VALUE_NONLOCAL "*call_value_nonlocal_aixdi"
#endif
int plugin_is_GPL_compatible;
struct plugin_info plugin_info = {
.version = "1",
.help = PLUGIN_NAME ": insert nops after local calls\n",
};
static unsigned int ppc64le_plugin_execute(void)
{
rtx_insn *insn;
int code;
const char *name;
static int nonlocal_code = -1, local_code = -1,
value_nonlocal_code = -1, value_local_code = -1;
static bool initialized = false;
if (initialized)
goto found;
/* Find the rs6000.md code numbers for local and non-local calls */
initialized = true;
for (code = 0; code < 1000; code++) {
name = get_insn_name(code);
if (!name)
continue;
if (!strcmp(name , CALL_LOCAL))
local_code = code;
else if (!strcmp(name , CALL_NONLOCAL))
nonlocal_code = code;
else if (!strcmp(name, CALL_VALUE_LOCAL))
value_local_code = code;
else if (!strcmp(name, CALL_VALUE_NONLOCAL))
value_nonlocal_code = code;
if (nonlocal_code != -1 && local_code != -1 &&
value_nonlocal_code != -1 && value_local_code != -1)
goto found;
}
found:
if (nonlocal_code == -1 || local_code == -1 ||
value_nonlocal_code == -1 || value_local_code == -1) {
error("%s: cannot find call instruction codes", PLUGIN_NAME);
}
/* Convert local calls to non-local */
for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
if (GET_CODE(insn) == CALL_INSN) {
if (INSN_CODE(insn) == local_code)
INSN_CODE(insn) = nonlocal_code;
else if (INSN_CODE(insn) == value_local_code)
INSN_CODE(insn) = value_nonlocal_code;
}
}
return 0;
}
#define PASS_NAME ppc64le_plugin
#define NO_GATE
#include "gcc-generate-rtl-pass.h"
int plugin_init(struct plugin_name_args *plugin_info,
struct plugin_gcc_version *version)
{
const char * const plugin_name = plugin_info->base_name;
PASS_INFO(ppc64le_plugin, "vregs", 1, PASS_POS_INSERT_AFTER);
if (!plugin_default_version_check(version, &gcc_version))
error(1, 0, PLUGIN_NAME ": incompatible gcc/plugin versions");
register_callback(plugin_name, PLUGIN_INFO, NULL, &plugin_info);
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
&ppc64le_plugin_pass_info);
return 0;
}