跳转至

Programming

C & C++: Debug Print like icecream in Python

导言

调试多进程的复杂C++程序的时候,经常会有难以GDB,反而主要依靠简单的print和cout来打印相关信息。这个时候我就想起来python的icecream库1是真的好用。

为此我开始调研C++有没有相关的库,思考一个好用的库应该有哪些功能,具体实现方式应该如何。

The CUDA Execution Model

导言

The CUDA Execution Model: how the CUDA architecture handles the execution of code in parallel.

这篇将聚焦于CUDA的基础知识,基本概念,

Cuda Driver Runtime

导言

Divide the bulky and outdated content about cuda runtime env into individual posts, ensuring both the thematic integrity and a balanced size for each blog entry.

C Program Compile Problems

TODO:[5] please fix all in free time

Overview

版本冲突的几个主要原因:

  1. 老项目会自己开发New func & macro/definitions
  2. New sys-header also develop new func & macro/definitions
  3. Conflict1: redefinition of the same macro/definitions. 大家都需要某个功能,老项目原本自己写了这部分代码。随着时间的发展 merge 到了sys-file。old project compile in new sys with the diff code conflict for same purpose.
    1. FIX: delete the old project code, and use the sys STL
  4. 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.
    1. FIX: update old project to support the new func (because you can not degrade the sys-files).

tricks

  1. find definition xxx in header search path
ag -us "def.*xxx" /usr/include /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include
  1. After each updates(code changing), you should guarantee the benchmark(official makefile/simple testcase) compile maintain the correct compilation.

1

compile multipim with pin3.28 under g++11

/usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:44:19: error: missing binary operator before token "(" 
4| #if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
  1. 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()
  2. I successfully found head file in directory PIN/extras/crt/include/features.h
  3. fix by remove or adjust the head file searching order?
    1. just rename to feature_bk.h

1.1

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)                  \
      |                                                       ^     

We find the definition

# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0 on git:main x [16:45:13] C:2
$ ag -us "__glibc_clang_prereq" /usr/include ./pin ./common ./build/opt /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include
/usr/include/features.h
179:# define __glibc_clang_prereq(maj, min) \
182:# define __glibc_clang_prereq(maj, min) 0
413:# elif _FORTIFY_SOURCE > 2 && (__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

#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.

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;                                               
      |                                  ^~~~~~~~~~~          

error: initializer but incomplete type is caused by compiler-think undefined type.

But the define is just before lines typedef __locale_t __c_locale;

And found the conflict defined

# 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

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.  */
  const unsigned short int *__ctype_b;
  const int *__ctype_tolower;
  const int *__ctype_toupper;

  /* Note: LC_ALL is not a valid index into this array.  */
  const char *__names[13];
};

typedef struct __locale_struct *__locale_t;
typedef __locale_t locale_t;

4

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 __THROW macro is correctly defined or included in your code.

$ ag -us "def.*__THROW" /usr/include ./pin ./common ./build/opt /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include
/usr/include/x86_64-linux-gnu/sys/cdefs.h
79:#  define __THROW    __attribute__ ((__nothrow__ __LEAF))
80:#  define __THROWNL  __attribute__ ((__nothrow__))
86:#    define __THROW  noexcept (true)
88:#    define __THROW  throw ()

So __THROW is defined in /usr/include/x86_64-linux-gnu/sys/cdefs.h

Stupid idea is to sudo vim the sys-header stdlib.h add codes:

/* TSJ 231009: add for the miss of definition of __THROW */
#include <x86_64-linux-gnu/sys/cdefs.h>

4.1

In file included from build/opt/pin_cmd.cpp:30:
/usr/include/wordexp.h:66:45: error: expected initializer before '__THROW'
   66 | extern void wordfree (wordexp_t *__wordexp) __THROW;
      |                                             ^~~~~~~

# wordexp.h -> <features.h> -> sys/cdefs.h

The more likely scenario is pin-def cdefs.h lack the definition of macro __THROW

$ ag -usg "cdefs\.h" /usr/include ./pin ./common ./build/opt /usr/lib/gcc/x86_64-linux-gnu/11/include /usr/local/include
/usr/include/bsd/sys/cdefs.h
/usr/include/x86_64-linux-gnu/sys/cdefs.h
pin/extras/crt/include/sys/cdefs.h

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

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

# 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

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

# 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;

/usr/include/elf.h
52:typedef uint16_t Elf64_Section;
532:  Elf64_Section     st_shndx;               /* Section index */

the reason is header higher search priority

$ 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

/* Type for section indices, which are 16-bit quantities.  */
typedef uint16_t Elf32_Section;
typedef uint16_t Elf64_Section;

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.

# 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;

6.1

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

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

# 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.

# 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

#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
# include <pthread.h>
...
#elif defined(_LIBCPP_HAS_THREAD_API_C11)
# include <threads.h>
#endif

So which file define _LIBCPP_HAS_THREAD_API_PTHREAD

$ 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.

7.1

# pass
# shaojiemike @ icarus0 in ~/github/MultiPIM_icarus0/pin/source/tools/ManualExamples on git:main x [10:02:19]
$  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/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/cxx/include -isystem /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include -isystem /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include/arch-x86_64 -isystem /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include/kernel/uapi -isystem /staff/shaojiemike/Download/pin-3.28-98749-g6643ecee5-gcc-linux/extras/crt/include/kernel/uapi/asm-x86 -I../../../extras/components/include -I../../../extras/xed-int
el64/include/xed -I../../../source/tools/Utils -I../../../source/tools/InstLib -O3 -fomit-frame-pointer -MD -c inscount0.cpp

# 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.

But we just change a little.

# 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

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);
      |                ^~~~~~~~~

Ref suggest us to test the macro define

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

# 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

g++ -o build/opt/dumptrace -Wl,-R/staff/shaojiemike/github/MultiPIM_icarus0/common/libconfig/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ build/opt/dumptrace.ot build/opt/access_tracing.ot build/opt/memory_hierarchy.ot build/opt/config.ot build/opt/galloc.ot build/opt/log.ot build/opt/pin_cmd.ot -Lcommon/libconfig/lib -lconfig++ -lhdf5 -lhdf5_hl

/usr/bin/ld: build/opt/dumptrace.ot: in function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string<decltype(nullptr)>(char const*)':
/staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/cxx/include/string:841: undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)'

After reading the code, template function init denifition seems no problem. So the first judgement is this is due to the new pin lib missing.

9.1 : crude solution

Copy all missing lib from inscount0.so

g++ -o build/opt/dumptrace -Wl,--hash-style=sysv /staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/runtime/pincrt/crtbeginS.o -Wl,-Bsymbolic -Wl,--version-script=/staff/shaojiemike/github/MultiPIM_icarus0/pin/source/include/pin/pintool.ver -fabi-version=2 -Wl,-R/staff/shaojiemike/github/MultiPIM_icarus0/common/libconfig/lib -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/runtime/pincrt -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/lib -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/lib-ext -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/xed-intel64/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ build/opt/dumptrace.ot build/opt/access_tracing.ot build/opt/memory_hierarchy.ot build/opt/config.ot build/opt/galloc.ot build/opt/log.ot build/opt/pin_cmd.ot -Lcommon/libconfig/lib -lconfig++ -lhdf5 -lhdf5_hl -lpin -lxed /staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/runtime/pincrt/crtendS.o -lpindwarf -ldl-dynamic -nostdlib -lc++ -lc++abi -lm-dynamic -lc-dynamic -lunwind-dynamic

which lead error

/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

int main(int argc, const char* argv[]) {
    InitLog(""); //no log header
    if (argc != 2) {
        info("Prints an access trace");
        info("Usage: %s <trace>", argv[0]);
        exit(1);
    }
    ...}

9.2 pick in details

dumptrace is executable and inscount0.so is a dynamic library. We should analyse the lack part.

First we try to delete part and lower pin-lib priority

g++ -o build/opt/dumptrace -Wl,-R/staff/shaojiemike/github/MultiPIM_icarus0/common/libconfig/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ build/opt/dumptrace.ot build/opt/access_tracing.ot build/opt/memory_hierarchy.ot build/opt/config.ot build/opt/galloc.ot build/opt/log.ot build/opt/pin_cmd.ot -Lcommon/libconfig/lib -lconfig++ -lhdf5 -lhdf5_hl  -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/runtime/pincrt -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/lib -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/intel64/lib-ext -L/staff/shaojiemike/github/MultiPIM_icarus0/pin/extras/xed-intel64/lib -lpin -lxed -lpindwarf -ldl-dynamic -nostdlib -lc++ -lc++abi -lm-dynamic -lc-dynamic -lunwind-dynamic

which alse error with __cxa_get_exception_ptr@@CXXABI_1.3.1 and error adding symbols: DSO missing from command line

TODO: ???

9.3

/usr/bin/ld: build/opt/dumptrace.ot: in function `AccessTraceReader::read()':
/staff/shaojiemike/github/MultiPIM_icarus0/build/opt/access_tracing.h:70: undefined reference to `__assert2'

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

上面回答部分来自ChatGPT-3.5,没有进行正确性的交叉校验。

C++ ABI

ABI (Application Binary Interface)

According to REF

“ library API + compiler ABI = library ABI ”

  1. library API(Application Programing Interface)
  2. e.g., types/functions/exceptionsSTH in (STL) include files
  3. compiler Application Binary Interface, or ABI
  4. sth during the compilation process, e.g., alignment/funcNameHandling

example:

TODO:

  1. the different version lead to what during the compilation
  2. why we miss this during small C project programming.

ABI Management

We are talking about GNU G++ support

  1. Release versioning on the libstdc++.so binary
  2. e.g, GCC 11.1.0 using libstdc++.so.6.0.29 icarus0 11.4.0 using previous version in document
  3. Symbol versioning on the libstdc++.so binary.
  4. mapfile: libstdc++-v3/config/abi/pre/gnu.ver in github code which shows the detail symbol in diff-verion.
  5. GCC 11.1.0: GLIBCXX_3.4.29, CXXABI_1.3.13

Usage

which verisons can be chosen

TODO: Is there a way to lower the abi verison during the compilation

how to change when compile

The GNU C++ compiler, g++, has a compiler command line option to switch between various different C++ ABIs. This explicit version switch is the flag -fabi-version. In addition, some g++ command line options may change the ABI as a side-effect of use. Such flags include -fpack-struct and -fno-exceptions, but include others: see the complete list in the GCC manual under the heading Options for Code Generation Conventions.

-fabi-version=n | Use version n of the C++ ABI. The default is version 0.(Version 2 is the version of the C++ ABI that first appeared in G++ 3.4, and was the default through G++ 4.9.) ABI: an application binary interface (ABI) is an interface between two binary program modules. Often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.

check the veriosn a program using

ldd -v /bin/ls show many libc.so.6 in different GLIBC version, chatGPT explain this due to maintain backward compatibility as much as possible to ensure that older programs continue to work on newer systems. This is achieved through versioned symbols and by providing multiple versions of shared libraries.

TODO: If i write a simple C program using DLL, what is the ldd -v print out? will be a simgle verison of libc.so.6? or the equal question is If /bin/ls use diff api in diff versions of DDL.

old program request which version

TODO:

PROBLEM: ABI compability

during the pintool compilation process

#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:

  1. check the project using which ABI to program
  2. Is there a way to lower the abi verison during the compilation
  3. or compile a program using

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

上面回答部分来自ChatGPT-3.5,没有进行正确性的交叉校验。