New sys-header also develop new func & macro/definitions
Conflict1: redefinition of the same macro/definitions. 大家都需要某个功能,老项目原本自己写了这部分代码。随着时间的发展 merge 到了sys-file。old project compile in new sys with the diff code conflict for same purpose.
FIX: delete the old project code, and use the sys STL
Conflict2: New sys develop a new func(e.g., __THROW) in it’s header files, part sys header(e.g, iostream) is included by old project, but the definition of new func is not included for lower search priority.
FIX: update old project to support the new func (because you can not degrade the sys-files).
tricks
find definition xxx in header search path
1
ag -us "def.*xxx" /usr/include /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include
After each updates(code changing), you should guarantee the benchmark(official makefile/simple testcase) compile maintain the correct compilation.
SO(StackOverflow) show similar errors, I guess the Gabriel Devillers answer the key point, self head file’s higher priority lead to the no define of __GLIBC_PREREQ()
I successfully found head file in directory PIN/extras/crt/include/features.h
fix by remove or adjust the head file searching order?
just rename to feature_bk.h
1.1
1 2 3 4 5 6 7 8 9 10
In file included from pin/extras/crt/include/sys/cdefs.h:84, from pin/extras/crt/include/features.h:33, from pin/extras/cxx/include/__config:228, from pin/extras/cxx/include/string:510, from build/opt/g_std/g_string.h:31, from build/opt/access_tracing.h:29, from build/opt/access_tracing.cpp:26: /usr/include/x86_64-linux-gnu/sys/cdefs.h:146:55: error: missing binary operator before token "(" 146 | #if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \ | ^
TODO: maybe include_next in pin/extras/crt/include/features.h
2
during the officail pintool compilation of pin2.14 under g++11
1 2 3
#if !defined(__GXX_ABI_VERSION) || CC_USED_ABI_VERSION != __GXX_ABI_VERSION #error The C++ ABI of your compiler does not match the ABI of the pin kit. #endif
TODO:
3
compile multipim with pin3.28 under g++11 after adding crt include path.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
In file included from /usr/include/c++/11/bits/localefwd.h:40, from /usr/include/c++/11/string:43, from build/opt/g_std/g_string.h:31, from build/opt/access_tracing.h:29, from build/opt/access_tracing.cpp:26: /usr/include/x86_64-linux-gnu/c++/11/bits/c++locale.h: In function'int std::__convert_from_v(const __c_locale&, char*, int, const char*, ...)': /usr/include/x86_64-linux-gnu/c++/11/bits/c++locale.h:75:16: error: variable 'std::__c_locale __old' has initializer but incomplete type 75 | __c_locale __old = __gnu_cxx::__uselocale(__cloc); | ^~~~~ /usr/include/x86_64-linux-gnu/c++/11/bits/c++locale.h:75:47: error: cannot convert 'const __c_locale' to 'locale_t' {aka '__locale_t*'} 75 | __c_locale __old = __gnu_cxx::__uselocale(__cloc); | ^~~~~~ | | | const __c_locale /usr/include/x86_64-linux-gnu/c++/11/bits/c++locale.h:52:34: note: initializing argument 1 of '__locale_t* __gnu_cxx::__uselocale(locale_t)' 52 | extern "C" __typeof(uselocale) __uselocale; | ^~~~~~~~~~~
But the define is just before lines typedef __locale_t __c_locale;
And found the conflict defined
1 2 3 4 5
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0/pin on git:main x [9:56:26] $ ag __locale_t extras/crt/include/xlocale.h 33:struct __locale_t; 34:typedef struct __locale_t* locale_t;
replace these two lines to std header file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
struct__locale_struct { /* Note: LC_ALL is not a valid index into this array. */ struct__locale_data *__locales[13]; /* 13 = __LC_LAST. */
/* To increase the speed of this solution we add some special members. */ constunsignedshortint *__ctype_b; constint *__ctype_tolower; constint *__ctype_toupper;
/* Note: LC_ALL is not a valid index into this array. */ constchar *__names[13]; };
In file included from /usr/include/c++/11/cstdlib:75, from /usr/include/c++/11/ext/string_conversions.h:41, from /usr/include/c++/11/bits/basic_string.h:6608, from /usr/include/c++/11/string:55, from build/opt/g_std/g_string.h:31, from build/opt/access_tracing.h:29, from build/opt/access_tracing.cpp:26: /usr/include/stdlib.h:97: note: this is the location of the previous definition 97 | #define MB_CUR_MAX (__ctype_get_mb_cur_max ()) | /usr/include/stdlib.h:98:45: error: expected initializer before '__THROW' 98 | extern size_t __ctype_get_mb_cur_max (void) __THROW __wur; | ^~~~~~~
This shows error of the definition the __THROW. Ensure that the __THROWmacro is correctly defined or included in your code.
It’s a bad idea to include_next which lead to 7.1 error.
The easy solution is to degrade the wordexp.h with remove the only one macro __THROW.
5
1 2 3 4 5 6 7 8 9 10
In file included from pin/source/include/pin/pin.H:27, from build/opt/decoder.h:31, from build/opt/core.h:30, from build/opt/ooo_core.h:34, from build/opt/contention_sim.cpp:35: pin/extras/components/include/util/intel-fp.hpp: At global scope: pin/extras/components/include/util/intel-fp.hpp:21:9: error: 'UINT64' does not name a type; did you mean 'UINT64_C'? 21 | UINT64 _significand; ///< The floating-point significand. | ^~~~~~ | UINT64_C
Type is not defined, include to fix
1 2 3 4 5
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [16:16:38] $ ag ' UINT64;' pin/extras/crt/include/types.h 70:typedef unsigned __int64 UINT64; 86:typedef uint64_t UINT64;
5.1
1 2 3 4 5
In file included from build/opt/debug_zsim.cpp:28: /usr/include/gelf.h:70:9: error: 'Elf64_Section' does not name a type; did you mean 'Elf64_Ssize'? 70 | typedef Elf64_Section GElf_Section; | ^~~~~~~~~~~~~ | Elf64_Ssize
We found the definition
1 2 3 4 5 6 7 8
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [15:57:57] C:2 $ ag -us "Elf64_Section" /usr/include ./pin ./common ./build/opt /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include /usr/include/gelf.h 70:typedef Elf64_Section GElf_Section;
$ ag -usg "elf.h" /usr/include ./pin ./common ./build/opt /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include /usr/include/gelf.h /usr/include/elf.h pin/extras/crt/include/elf.h pin/extras/crt/include/freebsd/3rd-party/sys/x86/include/elf.h # used by pin/extras/crt/include/elf.h
We can not just add #include_next in pin’s elf.h due the redefined of many structs.
We fix it by add missing macro definitions in suitable header file pin/extras/crt/include/freebsd/3rd-party/include/elf.h
1 2 3
/* Type for section indices, which are 16-bit quantities. */ typedefuint16_t Elf32_Section; typedefuint16_t Elf64_Section;
6
1 2 3 4 5 6
In file included from pin/source/include/pin/pin.H:96, from build/opt/decoder.h:32, from build/opt/decoder.cpp:26: pin/source/include/pin/gen/ins_api_xed_ia32.PH:65:27: error: reference to 'USIZE' is ambiguous 65 | extern PIN_DEPRECATED_API USIZE INS_MemoryWriteSize(INS ins); | ^~~~~
conflict define in current path header and search path header, select one to comment.
1 2 3 4 5 6
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [16:39:02] $ ag ' USIZE;' pin pin/extras/crt/include/types.h 122:typedef ADDRINT USIZE; pin/source/include/pin/gen/types_foundation.PH 41:typedef unsigned int USIZE;
In file included from build/opt/slab_alloc.h:43, from build/opt/event_recorder.h:32, from build/opt/cache.cpp:29: build/opt/mutex.h: At global scope: build/opt/mutex.h:56:30: error: reference to 'mutex' is ambiguous 56 | class aligned_mutex : public mutex {} ATTR_LINE_ALIGNED; | ^~~~~ In file included from pin/extras/cxx/include/mutex:190, from pin/extras/cxx/include/__locale:18, from pin/extras/cxx/include/ios:215, from pin/extras/cxx/include/iostream:37, from build/opt/memory_hierarchy.h:32, from build/opt/cache_arrays.h:29, from build/opt/cache.h:29, from build/opt/cache.cpp:26: pin/extras/cxx/include/__mutex_base:32:78: note: candidates are: 'class std::__1::mutex' 32 | class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex | ^~~~~ In file included from build/opt/slab_alloc.h:43, from build/opt/event_recorder.h:32, from build/opt/cache.cpp:29: build/opt/mutex.h:34:7: note: 'class mutex' 34 | class mutex : public GlobAlloc { | ^~~~~
It seems the class redefine, we comment pintool part code to fix it.
7
1 2 3 4 5 6 7 8 9 10 11 12
In file included from pin/extras/cxx/include/mutex:190, from pin/extras/cxx/include/__locale:18, from pin/extras/cxx/include/ios:215, from pin/extras/cxx/include/iostream:37, from build/opt/memory_hierarchy.h:32, from build/opt/access_tracing.h:30, from build/opt/access_tracing.cpp:26: pin/extras/cxx/include/__mutex_base: In member function'void std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long int, std::__1::ratio<1, 1000000000> > >)': pin/extras/cxx/include/__mutex_base:508:16: error: 'pthread_cond_clockwait' was not declared in this scope; did you mean 'pthread_cond_wait'? 508 | int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts); | ^~~~~~~~~~~~~~~~~~~~~~ | pthread_cond_wait
After Reading header file, It seem compiler believe system contain the function.
TODO: 阅读system header file 的include和底层代码实现: 线程,print,syscall。e.g., pthread_cond_clockwait function is defined where
1 2 3 4
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [15:10:32] $ ag pthread_cond_clockwait /usr/include /usr/include/pthread.h 1171:extern int pthread_cond_clockwait (pthread_cond_t *__restrict __cond,
Of course,We assume pin/extras/crt/include/pthread.h has higher include priority. We will prove it in the later.
1 2 3 4 5 6 7 8
# the exsit include $ ag pthread.h pin/extras/cxx pin/extras/cxx/include/__threading_support 32:# include <pthread.h> # So who include __threading_support $ ag __threading_support pin/extras/cxx pin/extras/cxx/include/__mutex_base # the error header 16:#include <__threading_support>
Reading __threading_support code, the include under a #ifdef condition
So which file define _LIBCPP_HAS_THREAD_API_PTHREAD
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ ag -u _LIBCPP_HAS_THREAD_API_PTHREAD
pin/extras/cxx/include/__config 1134: !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 1149:# define _LIBCPP_HAS_THREAD_API_PTHREAD 1152:# define _LIBCPP_HAS_THREAD_API_PTHREAD 1160:#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1170:#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1171:#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 1199:#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
# second one define it # and find #include <__config> in the error header
According to -MMD option’s result .d file, we make sure include the pin/extras/cxx/include/__config one. And add #warning preprocessor directive or check -MD option result to make sure include <pthread.h>. But the point is include pin/extras/crt/include/pthread.h
First Idea: I believe that changing the potentially buggy Pin crt code is a bad idea. The more likely scenario is that we are using the crt incorrectly. So, let’s identify how to trigger the bug starting from build/opt/memory_hierarchy.h:32, and then replicate it in a simple pintool to verify whether we are indeed using it incorrectly.
But the real situation is pintool just #include <iostream> and the simple pintool also include without compilation error. Weird scenario deserves more research.
# failed # shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0/pin/source/tools/ManualExamples on git:main x [10:02:53] $ g++ -Wall -Werror -Wno-unknown-pragmas -DPIN_CRT=1 -fno-stack-protector -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX -fabi-version=2 -I../../../sou rce/include/pin -I../../../source/include/pin/gen -isystem /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include -isystem /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/crt/include -isystem /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/crt/include/arch-x86_64 -isystem /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/crt/include/kernel/uapi -isystem /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/crt/include/kernel/uapi/asm-x86 -I../../../extras/components/include -I../../../extras/xed-intel64/include/xed -I../../../source/tools/Utils -I../../../source/tools/InstLib -O3 -fomit-frame-pointer -MD -c inscount0.cpp In file included from /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/mutex:190, from /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/__locale:18, from /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/ios:215, from /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/iostream:37, from inscount0.cpp:6: /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/__mutex_base: In member function'void std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long int, std::__1::ratio<1, 1000000000> > >)': /staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/__mutex_base:508:16: error: 'pthread_cond_clockwait' was not declared in this scope; did you mean 'pthread_cond_wait'? 508 | int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts); | ^~~~~~~~~~~~~~~~~~~~~~ | pthread_cond_wait
After the compile compare, we decide the error is due to our change in pin code.
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [10:09:58] $ diff /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux pin diff '--color=auto' -r /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include/features.h pin/extras/crt/include/features.h 32a33 > #include_next <features.h> diff '--color=auto' -r /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include/freebsd/3rd-party/include/elf.h pin/extras/crt/include/freebsd/3rd-party/include/elf.h 42a43,46 > /* Type for section indices, which are 16-bit quantities. */ > typedef uint16_t Elf32_Section; > typedef uint16_t Elf64_Section; > diff '--color=auto' -r /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include/sys/cdefs.h pin/extras/crt/include/sys/cdefs.h 44a45 > 82a84,114 > #include_next <sys/cdefs.h> > > > /* GCC can always grok prototypes. For C++ programs we add throw() > to help it optimize the function calls. But this only works with > gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions > as non-throwing using a function attribute since programs can use > the -fexceptions options for C code as well. */ > // # if !defined __cplusplus \ > // && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__)) > // # define __THROW __attribute__ ((__nothrow__ __LEAF)) > // # define __THROWNL __attribute__ ((__nothrow__)) > // # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct > // # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct > // # else > // # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4) > // # if __cplusplus >= 201103L > // # define __THROW noexcept (true) > // # else > // # define __THROW throw () > // # endif > // # define __THROWNL __THROW > // # define __NTH(fct) __LEAF_ATTR fct __THROW > // # define __NTHNL(fct) fct __THROW > // # else > // # define __THROW > // # define __THROWNL > // # define __NTH(fct) fct > // # define __NTHNL(fct) fct > // # endif > // # endif
Rollback two include_next to pass the benchmark.
8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
In file included from pin/extras/cxx/include/limits.h:57, from pin/extras/cxx/include/climits:41, from pin/extras/cxx/include/ratio:82, from pin/extras/cxx/include/chrono:830, from pin/extras/cxx/include/__threading_support:15, from pin/extras/cxx/include/atomic:579, from pin/extras/cxx/include/memory:687, from pin/extras/cxx/include/algorithm:653, from pin/extras/cxx/include/__string:57, from pin/extras/cxx/include/string_view:179, from pin/extras/cxx/include/string:511, from build/opt/g_std/g_string.h:31, from build/opt/access_tracing.h:29, from build/opt/access_tracing.cpp:26: build/opt/common/global_const.h:32:16: error: expected unqualified-id before numeric constant 32 | const unsigned PAGE_SIZE=(1UL<<PAGE_SHIFT); | ^~~~~~~~~
In file included from build/opt/common/common_structures.h:20, from build/opt/memory_hierarchy.h:39, from build/opt/access_tracing.h:30, from build/opt/access_tracing.cpp:26: build/opt/common/global_const.h:33:2: error: #error "PAGE_SIZE is defined" 33 | #error "PAGE_SIZE is defined" | ^~~~~
and we find the redefined in
1 2 3 4 5 6
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [10:28:46] $ ag -u "define PAGE_SIZE" pin/extras/crt/include/limits.h 124:#define PAGE_SIZE 4096 pin/extras/crt/include/kernel/uapi/linux/a.out.h 120:#define PAGE_SIZE 0x400
FIX: set #ifdef in old pintool code.
9 ld
During the zsim-like multipim compilation, dumptrace
/usr/bin/ld: build/opt/config.ot: undefined reference to symbol '__cxa_get_exception_ptr@@CXXABI_1.3.1' /usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
forget add -shared option to eliminate the error msg, but the I guess build/opt/dumptrace is an excutable, because the code