Compiling fails with USE_INTEL_JITEVENTS, USE_OPROFILE_JITEVENTS and USE_PERF_JITEVENTS = 1

First time posting here: I’m building Julia from source to enable external profiling for all three tools

The build fails with:

/home/tippit/julia/src/init.c: In function ‘_julia_init’:
/home/tippit/julia/src/init.c:697:17: error: redefinition of ‘jit_profiling’
  697 |     const char *jit_profiling = getenv("ENABLE_JITPROFILING");
      |                 ^~~~~~~~~~~~~
/home/tippit/julia/src/init.c:683:17: note: previous definition of ‘jit_profiling’ was here
  683 |     const char *jit_profiling = getenv("ENABLE_JITPROFILING");

Make.user looks like this:

USE_BINARYBUILDER=0
USE_BINARYBUILDER_LLVM=0
USE_INTEL_JITEVENTS=1
USE_PROFILE_JITEVENTS=1
USE_PERF_JITEVENTS=1

My temporary fix to compile was to comment out lines 690 and 697 in src/init.c to avoid the redefinition, but I’ve since rebuilt successfully with init.c lines 682-710 like this:

#if defined(JL_USE_INTEL_JITEVENTS)
#if !defined(JIT_PROFILING_ENABLED)
#define JIT_PROFILING_ENABLED
    const char *jit_profiling = getenv("ENABLE_JITPROFILING");
#endif
    if (jit_profiling && atoi(jit_profiling)) {
        jl_using_intel_jitevents = 1;
    }
#endif

#if defined(JL_USE_OPROFILE_JITEVENTS)
#if !defined(JIT_PROFILING_ENABLED)
#define JIT_PROFILING_ENABLED
    const char *jit_profiling = getenv("ENABLE_JITPROFILING");
#endif
    if (jit_profiling && atoi(jit_profiling)) {
        jl_using_oprofile_jitevents = 1;
    }
#endif

#if defined(JL_USE_PERF_JITEVENTS)
#if !defined(JIT_PROFILING_ENABLED)
#define JIT_PROFILING_ENABLED
    const char *jit_profiling = getenv("ENABLE_JITPROFILING");
#endif
    if (jit_profiling && atoi(jit_profiling)) {
        jl_using_perf_jitevents= 1;
    }
#endif

Is this worth opening an issue? Is that a clean solution to the problem?

Thank you!

Please do open a PR! Normally we only assume that you enable one integration, but if there is a good use-case for wanting multiple integrations I don’t see the harm in allowing more. Although I would hoist the const char *jit_profiling = getenv("ENABLE_JITPROFILING"); into it’s own pre-processor statment instead of doing the:

#if !defined(JIT_PROFILING_ENABLED)
#define JIT_PROFILING_ENABLED

Thanks for the response! You’ll have to forgive me - it’s been a bit since I’ve used C. Are you saying instead do something like:

#if \
    defined(JL_USE_INTEL_JITEVENTS) || \
    defined(JL_USE_OPROFILE_JITEVENTS) || \
    defined(JL_USE_PERF_JITEVENTS)
    const char *jit_profiling = getenv("ENABLE_JITPROFILING");
#endif

Above the other statements?

1 Like

I’d like to say I got the same bug and this should probably be fixed in the next minor update (not sure why it wasn’t already).