blob: 5c5eece1d5c2d93687eec02cbd2cf83df297f051 [file] [log] [blame]
tom2878c812005-11-07 18:06:10 +00001-------------------------------------------------------------------
2Guide to multiple architecture support
3-------------------------------------------------------------------
4
sewardj01262142006-01-04 01:20:28 +00005What is achieved
6~~~~~~~~~~~~~~~~
7Valgrind supports systems where binaries for more than one
8architecture can be run. The current arrangements build:
tom2878c812005-11-07 18:06:10 +00009
sewardj01262142006-01-04 01:20:28 +000010- single-arch support on x86 and ppc32 systems
11- dual-arch support on amd64 and ppc64 systems
tom2878c812005-11-07 18:06:10 +000012
sewardj01262142006-01-04 01:20:28 +000013To support this the valgrind build system can now build multiple
14versions of the coregrind library and of VEX, and then build and link
15multiple versions of each tool.
16
17A central notion is that of 'primary' vs 'secondary' platforms. The
18system is built in its entirety for the primary platform, including
19performance and regression suites and all auxiliary programs. For
20dual-arch systems, the primary platform is amd64 and ppc64
21respectively.
22
23On dual-arch systems, there is a 'secondary' target - x86 and ppc32
24respectively. The tools are built again for the secondary target, and
25the 'valgrind' launcher program can handle executables for either the
26primary or secondary target. However, the regression and performance
27tests and everything else is not rebuilt for the secondary target.
28
29On single-arch systems, there is no secondary target.
30
31
32How the build system does that
33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34The keys to understanding this are in:
35
36- configure.in
37- Makefile.flags.am
38- <tool>/tests/Makefile.am
39- <tool>/tests/<arch>/Makefile.am
40- perf/Makefile.am
41
42The configure script inspects the CPU. It then sets
43
44 VG_PLATFORM_PRI to be the primary target
45 VG_PLATFORM_SEC to be the secondary target, if any
46
sewardj01262142006-01-04 01:20:28 +000047It also sets one (single-arch build) or two (dual-arch build) of
48the following:
tom2878c812005-11-07 18:06:10 +000049
50 VG_X86_LINUX
51 VG_AMD64_LINUX
52 VG_PPC32_LINUX
sewardj01262142006-01-04 01:20:28 +000053 VG_PPC64_LINUX
tom2878c812005-11-07 18:06:10 +000054
55On an amd64 system both VG_X86_LINUX and VG_AMD64_LINUX will be true
sewardj01262142006-01-04 01:20:28 +000056so that two versions of all the tools will be built. Similarly on a
57ppc64 system both VG_PPC32_LINUX and VG_PPC64_LINUX will be defined.
58For the amd64 example, the coregrind libraries will be named:
tom2878c812005-11-07 18:06:10 +000059
60 libcoregrind_x86_linux.a
61 libcoregrind_amd64_linux.a
62
63and the VEX libraries:
64
65 libvex_x86_linux.a
66 libvex_amd64_linux.a
67
68Each tool will then be built twice, along with any preload library
69for the tool and the core preload libraries. At install time one
70subdirectory will be created in the valgrind library directory for
71each supported platforms and the tools and shared objects will be
72installed in the appropriate place. On amd64 the result will be:
73
74 <prefix>/lib/valgrind
75 <prefix>/lib/valgrind/default.supp
76 <prefix>/lib/valgrind/glibc-2.4.supp
77 <prefix>/lib/valgrind/hp2ps
78 <prefix>/lib/valgrind/amd64-linux
79 <prefix>/lib/valgrind/amd64-linux/vgpreload_core.so
80 <prefix>/lib/valgrind/amd64-linux/vgpreload_massif.so
81 <prefix>/lib/valgrind/amd64-linux/cachegrind
82 <prefix>/lib/valgrind/amd64-linux/memcheck
83 <prefix>/lib/valgrind/amd64-linux/helgrind
84 <prefix>/lib/valgrind/amd64-linux/massif
85 <prefix>/lib/valgrind/amd64-linux/vgpreload_memcheck.so
86 <prefix>/lib/valgrind/amd64-linux/lackey
87 <prefix>/lib/valgrind/amd64-linux/none
88 <prefix>/lib/valgrind/amd64-linux/vgpreload_helgrind.so
89 <prefix>/lib/valgrind/xfree-3.supp
90 <prefix>/lib/valgrind/x86-linux
91 <prefix>/lib/valgrind/x86-linux/vgpreload_core.so
92 <prefix>/lib/valgrind/x86-linux/vgpreload_massif.so
93 <prefix>/lib/valgrind/x86-linux/cachegrind
94 <prefix>/lib/valgrind/x86-linux/memcheck
95 <prefix>/lib/valgrind/x86-linux/helgrind
96 <prefix>/lib/valgrind/x86-linux/massif
97 <prefix>/lib/valgrind/x86-linux/vgpreload_memcheck.so
98 <prefix>/lib/valgrind/x86-linux/lackey
99 <prefix>/lib/valgrind/x86-linux/none
100 <prefix>/lib/valgrind/x86-linux/vgpreload_helgrind.so
101 <prefix>/lib/valgrind/glibc-2.3.supp
102 <prefix>/lib/valgrind/xfree-4.supp
103 <prefix>/lib/valgrind/glibc-2.2.supp
104
sewardj01262142006-01-04 01:20:28 +0000105The launcher program (ie the valgrind binary itself) is always built
106as a program for the primary target (so a 64 bit program on amd64 and
107ppc64) but will peek at the program which it is being asked to run and
108decide which of the possible tools to run taking both the requested
109tool and the format of the program being run into account.
tom2878c812005-11-07 18:06:10 +0000110
111Because the execv system call is now routed back through the launcher
112it is also possible to exec an x86 program from an amd64 program and
sewardj01262142006-01-04 01:20:28 +0000113vice versa. Ditto ppc32 and ppc64.
114
115
116Rules for Makefile.am hacking
117~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118In places where compilation should happen twice (on a dual-arch
119system), the decision about which directories and flags to use is
120guarded by the symbols:
121
122 VG_X86_LINUX
123 VG_AMD64_LINUX
124 VG_PPC32_LINUX
125 VG_PPC64_LINUX
126
127But there are also places where building must only happen once,
128for the primary architecture. These places are (at least):
129
130* the launcher, valgrind.c
131* all the architecture-independent regression tests
132* the performance tests
133* optionally, auxilary programs like hp2ps and valgrind-listener
134
135In order to do that, we need to know what flags to use to build for
136the primary target, and in particular whether to hand -m32 or -m64 to
137gcc. This is where Makefile.flags.am comes in.
138
139At the bottom of that file are defined AM_CPPFLAGS_PRI, AM_CFLAGS_PRI
140and AM_CCASFLAGS_PRI that must be used for compiling for the primary
141architecture. For example, look in coregrind/Makefile.am, and you
142will see these flag-sets being used to build the launcher (valgrind).
143
144Also at the bottom of Makefile.flags.am, AM_FLAG_M3264_PRI is defined.
145This gives the -m32/-m64 flag needed to build for the primary target.
146That flag is also contained within AM_CFLAGS_PRI -- AM_FLAG_M3264_PRI
147merely facilitates getting hold of it without the surrounding gunk.
148
149This leads to the final complication: building the regression tests.
150Most of them are architecture-neutral and so should be built for the
151primary target. The /test/ Makefile.am's duly include
152AM_FLAG_M3264_PRI in the compilation invokations, and you should
153ensure you preserve that when adding more tests.
154
155However, there are some arch-specific test directories (eg,
156none/tests/ppc32, etc). In each of these, we implicitly 'know'
157whether -m32 or -m64 is the right thing to specify. So instead of
158messing with AM_FLAG_M3264_PRI, these directories merely specific
159@FLAG_M32@ or @FLAG_M64@ directly. (These two symbols are also
160automagically set up by configure.in. Do not use -m32 and -m64
sewardje95d94f2008-09-19 09:02:19 +0000161directly - older compilers barf on them). Another reason not to
162use -m32 and -m64 directly is that they are called -maix32 and
163-maix64 on AIX; once again this is taken care of properly if you
164use @FLAG_M32@ and @FLAG_M64@ instead.