-
Notifications
You must be signed in to change notification settings - Fork 27
/
advtool-cross-compilers
454 lines (380 loc) · 18.9 KB
/
advtool-cross-compilers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<style type="text/css">/* Add a black background color to the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Add an active class to highlight the current page */
.active {
background-color: #4CAF50;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
float: left;
overflow: hidden;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Style the links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover, .dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
.custom-padding-left-12px{
padding-left:12px;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
@media screen and (max-width: 1100px) {
.topnav a:not(:first-child), .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
.custom-padding-left-12px{
padding-left:10px;
}
}
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width:1100px) {
.topnav.responsive {position: relative;}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {float: none;}
.topnav.responsive .dropdown-content {position: relative;}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}
</style>
<!--start menu -->
<div class="topnav" id="myTopnav" style="background-color: black;"><span><a href="https://www.ibm.com/support/pages/advance-toolchain-linux-power">Get started</a> <a href="https://www.ibm.com/support/pages/advtool-install" style="">Installation</a> <a href="https://www.ibm.com/support/pages/advtool-usage" style="">Usage</a> <a href="https://www.ibm.com/support/pages/advtool-faq">FAQ</a> <a href="https://www.ibm.com/support/pages/advtool-cross-compilers">Cross-compiler</a> <a href="https://www.ibm.com/support/pages/advtool-updates">Release updates</a> <span> <span><a class="icon" href="javascript:void(0);" onclick="myFunction()">☰</a></span></span></span></div>
<!-- start header content -->
<div class="ibm-leadspace-fluid ibm-flex ibm-nospacing ibm-flex--wrap ibm-no-border ibm-padding-top-2 ibm-background-gray-80">
<div class="ibm-col-12-12 ibm-padding-top-1 ibm-padding-bottom-1 ibm-alternate-background">
<p class="ibm-h1">Advance Toolchain for Linux on Power cross-compiler</p>
<p>The Advance Toolchain provides cross-compilers that run on Intel x86 and generate code for Power that helps teams to start developing for Power without having immediate access to a POWER server. The cross-compiler provides a way to compile programs for POWER by using a x86 (i386) or x86-64 (amd64) computer, helping teams to start developing for POWER without having access to a server in the early development phase.</p>
</div>
<div class="ibm-col-12-4 ibm-padding-top-1 ibm-padding-bottom-1 ibm-alternate-background"><a class="ibm-inlinelink ibm-anchor-down-link ibm-h4" href="#install" style="">Install the cross-compiler</a></div>
<div class="ibm-col-12-4 ibm-padding-top-1 ibm-padding-bottom-1 ibm-alternate-background"><a class="ibm-inlinelink ibm-anchor-down-link ibm-h4" data-widget="adjustanchorlinks" href="#build">Build sample</a></div>
<div class="ibm-col-12-4 ibm-padding-top-1 ibm-padding-bottom-1 ibm-alternate-background"><a class="ibm-inlinelink ibm-anchor-down-link ibm-h4" href="#faq">FAQ</a></div>
</div>
<div class="ibm-band-fluid ibm-flex ibm-padding-top-2 ibm-padding-bottom-1">
<p class="custom-padding-left-12px ibm-h4">IBM Advance Toolchain for Linux on Power 15.0-4 is now available! <a class="ibm-forward-link ibm-inlinelink" href="https://github.com/advancetoolchain/advance-toolchain/releases/tag/at15.0-4" target="_blank">Learn more</a></p>
</div>
<div class="ibm-band-fluid ibm-flex ibm-nospacing ibm-flex--wrap">
<div class="ibm-col-12-3 ibm-padding-top-1">
<p class="ibm-h3" id="install">Install the cross-compiler</p>
</div>
<div class="ibm-col-12-9 ibm-padding-top-1">
<div class="ibm-graphic-tabs ibm-graphic-tabs--colored" data-widget="dyntabs"><!-- Tabs here: -->
<div class="ibm-tab-section" id="crosscompilerinstalltabs">
<ul class="ibm-tabs" role="tablist">
<li class="ibm-active" role="presentation"><a aria-selected="true" href="#compilerrhel" role="tab">On Red Hat</a></li>
<li role="presentation"><a href="#compilersles" role="tab">On SLES</a></li>
<li role="presentation"><a href="#compilerubuntu" role="tab">On Ubuntu or Debian</a></li>
</ul>
</div>
<!-- Tabs content body with tab contents divs inside: -->
<div class="ibm-container-body ibm-background-white-core">
<div class="ibm-tabs-content" id="compilerrhel">
<p class="ibm-light">Use these steps to download the public key, create a repository configuration file, and install the cross-compiler package.</p>
<ol>
<li>The <code>gpg</code> public key is provided in the IBM repositories. This public key is used to verify the authenticity of both the Advance Toolchain packages and the repository contents. Download the <code>gpg</code> public key for your Linux distribution and import it by using the following commands, replacing <em>RHELX</em> with the Red Hat release that you are using and <em>PUBKEY</em> with its respective value.
<ul>
<li>For RHEL8, the <code>gpg</code> public key is: <code>gpg-pubkey-6976a827-5164221b</code></li>
<li>For RHEL9, the <code>gpg</code> public key is: <code>gpg-pubkey-615d762f-62f504a1</code></li>
</ul>
<pre>
wget https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/<em>RHELX</em>/<em>PUBKEY</em>
sudo rpm --import <em>PUBKEY</em>
</pre>
</li>
<li>Create a configuration file for the Advance Toolchain repository configuration file: <code>/etc/yum.repos.d/<em>advance-toolchain.repo</em></code>. Add the following content:
<pre>
# Begin of configuration file
[advance-toolchain]
name=Advance Toolchain IBM FTP
baseurl=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/<em>RHELX</em>
enabled=1
gpgcheck=1
gpgkey=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/<em>RHELX</em>/<em>PUBKEY</em>
# End of configuration file
</pre>
</li>
<li>Install the cross-compiler by running <code>yum install</code>: <code>yum install advance-toolchain-atX.X-cross-ppc64le</code></li>
</ol>
</div>
</div>
<!-- Tabs content body with tab contents divs inside: -->
<div class="ibm-container-body ibm-background-white-core">
<div class="ibm-tabs-content" id="compilersles">
<p class="ibm-light">Use these steps to download the public key, create a repository configuration file, and install the Advance Toolchain packages.</p>
<ol>
<li>The <code>gpg</code> public key <code>gpg-pubkey-6976a827-5164221b</code> is provided in the IBM repositories. This public key is used to verify the authenticity of both the Advance Toolchain packages and the repository contents. Download the <code>gpg</code> public key for your Linux distribution and import it by using the following commands:
<pre>
wget https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/redhat/RHEL8/gpg-pubkey-6976a827-5164221b
rpm --import gpg-pubkey-6976a827-5164221b
</pre>
</li>
<li>Create a configuration file for the Advance Toolchain repository configuration file: <code>/etc/yum.repos.d/advance-toolchain.repo</code>. Add the following content:
<pre>
# Begin of configuration file
[advance-toolchain]
name=Advance Toolchain IBM FTP
baseurl=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/suse/SLES_15
enabled=1
gpgcheck=1
gpgkey=https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/suse/SLES_15/gpg-pubkey-6976a827-5164221b
# End of configuration file
</pre>
</li>
<li>To install the cross-compiler by using <code>YAST</code>, follow these steps:
<ol>
<li>Run <code>yast2</code> as root.</li>
<li>Select Add-on Product.</li>
<li>From Media Type, select the FTP Protocol: <code>(x) FTP...</code></li>
<li>Under Server name, enter <code>public.dhe.ibm.com</code>.</li>
<li>Under Directory on Server, enter <code>/software/server/POWER/Linux/toolchain/at/suse/SLES_15</code>
<p>You get a warning about there being no product information available. The warning shows up because the <code>repomd-based</code> repository does not contain the <code>YaST</code> product information. It's not a bug. Select [Continue].</p>
</li>
<li>Under the Software Management interface, search for "advance toolchain", and select <code>advance-toolchain-atX.X-cross-ppc64le</code> or <code>advance-toolchain-atX.X-cross-ppc64le</code>.</li>
</ol>
</li>
<li>To install the cross-compiler with <code>Zypper</code>:
<ol>
<li>As root, add the IBM FTP to the repository list:
<pre>
zypper addrepo https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/suse/SLES_15 "Advance Toolchain"
</pre>
<p>This command creates a new repository entry called "Advance Toolchain" pointing to the IBM FTP site</p>
</li>
<li>To install the cross-compiler, run the following command: <code>zypper install advance-toolchain-atX.X-cross-ppc64le</code></li>
</ol>
</li>
</ol>
</div>
</div>
<div class="ibm-container-body ibm-background-white-core">
<div class="ibm-tabs-content" id="compilerubuntu">
<p class="ibm-light">Use these steps to download the public key, create a repository configuration file, and install the cross-compiler package</p>
<ol>
<li>The <code>gpg</code> public key is provided in the IBM repositories. This public key is used to verify the authenticity of both the Advance Toolchain packages and the repository contents. Download the <code>gpg</code> public key for your Linux distribution and import it by using the following commands:
<ul>
<li>For Ubuntu 20.04 or Ubuntu 18.04:
<pre>
wget https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu/dists/focal/6976a827.gpg.key
sudo apt-key add 6976a827.gpg.key
</pre>
</li>
<li>For Debian 11 or Ubuntu 22.04:
<pre>
wget -qO- https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu/dists/jammy/615d762f.gpg.key | sudo tee -a /etc/apt/trusted.gpg.d/615d762f.asc
</pre>
</li>
</ul>
</li>
<li>Configure the Advance Toolchain repositories by adding the following line to <code>/etc/apt/sources.list</code>:
<p>On ppc64el or amd64:</p>
<ul>
<li>When you install on Ubuntu 22.04 (jammy), Ubuntu 20.04 (focal) or Ubuntu 18.04 (bionic), point to its respective repository:
<pre>
deb [signed-by=/etc/apt/trusted.gpg.d/615d762f.asc] https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu jammy atX.X
deb https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu focal atX.X
deb https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/ubuntu bionic atX.X
</pre>
</li>
<li>When you install on Debian 11 (bullseye), point to:
<pre>
deb [signed-by=/etc/apt/trusted.gpg.d/615d762f.asc] https://public.dhe.ibm.com/software/server/POWER/Linux/toolchain/at/debian bullseye atX.X
</pre>
</li>
</ul>
</li>
<li>Refresh the cache by running: <code>sudo aptitude update</code> or <code>sudo apt update</code>.</li>
<li>Install the cross-compiler by running <code>sudo aptitude install advance-toolchain-atX.X-cross-ppc64le</code> or <code>sudo apt install advance-toolchain-atX.X-cross-ppc64</code>le.</li>
</ol>
<p>APT supports package upgrades for new revision releases (that is 7.1-0 to 7.1-1). For new major releases (that is 7.1-1 to 8.0-0), proceed as in a normal installation.</p>
</div>
</div>
</div>
</div>
<div class="ibm-col-12-12" style="background: #000;"></div>
</div>
<div class="ibm-band-fluid ibm-flex ibm-nospacing ibm-flex--wrap">
<div class="ibm-col-12-3 ibm-padding-top-1">
<p class="ibm-h3" id="build">Build a sample program</p>
</div>
<div class="ibm-col-12-9 ibm-padding-top-1">
<p><a href="https://www.gnu.org/software/wget/" target="_blank">GNU wget</a> is a small program that highlights the important problems when cross compiling a certain software: it depends on libraries provided by the Advance Toolchain cross-compiler and external libraries.</p>
<p>In this example, we build <code>GNU wget</code> for POWER little endian by using a x86 computer with the Advance Toolchain cross-compiler.</p>
<p class="ibm-h3">Copy headers and libraries</p>
<p>First, copy all necessary libraries and headers to a certain directory. This example uses the following libraries and headers:</p>
<ul>
<li>Headers: <code>${HOME}/wget/include</code></li>
<li>Libraries: <code>${HOME}/wget/lib</code></li>
</ul>
<p>In this case, ${HOME} is a shell variable holding the path of my home directory.</p>
<p>For <code>GNU wget</code>, we need to provide some <code>OpenSSL</code> libraries and <code>Zlib</code>. Both of them are available in the Advance Toolchain native compiler. However, the list of necessary libraries might vary according to the project. If you don't know well the project, you can use the following tools in order to identify the list of libraries they use:</p>
<pre>
ldd <executable>
rpm -q --requires -p <package.rpm>
dpkg-deb -f <package.deb> | grep "Depends:"
</pre>
<p>Usually the list of libraries necessary to build a project is the same across all processor architectures. So, you might use the previous commands against an executable or package compiled for another processor.</p>
<p>Here is the list of files required in order to build <code>wget</code>:</p>
<pre>
$ ls -1 ${HOME}/wget/include/
openssl/
zconf.h
zlib.h
$ ls -1 ${HOME}/wget/lib/
libcrypto.so
libcrypto.so.1.0.0
libssl.so
libssl.so.1.0.0
libz.so
libz.so.1
libz.so.1.2.6
</pre>
<p>Make sure the libraries are compiled for the target processor. If they don't match, you don't be able to use them. You might use <code>readelf -h</code> to verify this information:</p>
<pre>
$ /opt/at7.1/bin/powerpc64le-linux-gnu-readelf -h ${HOME}/wget/lib/libz.so.1.2.6
...
Data: 2's complement, little endian
...
Machine: PowerPC64
...
</pre>
<p class="ibm-h3">Build</p>
<p>With the header files and libraries in place, the system is ready to start the build. So, create a separate build directory:</p>
<pre>
mkdir ${HOME}/wget/build && cd ${HOME}/wget/build
</pre>
<p>After you enter the separate build directory, it's possible to configure the build by running:</p>
<pre>
CC=/opt/at7.1/bin/powerpc64le-linux-gnu-gcc \
CFLAGS="-I${HOME}/wget/include" \
LDFLAGS="-L${HOME}/wget/lib" \
../wget-1.15/configure \
--host=powerpc64le-linux \
--with-ssl=openssl
</pre>
<p>Where:</p>
<ul>
<li>The variable <code>CC</code> specifies which compiler to use. In this case, Advance Toolchain 7.1 cross-compiler for POWER little endian. Cross-compilers usually have a prefix in their program name to clearly indicate they don't generate executable code for the current processor. In this case, the prefix is "<code>powerpc64le-linux-gnu-</code>". This rule applies to all programs, for example: <code>g++</code>, <code>gdb</code>, <code>ld</code>, <code>as</code>, etc</li>
<li>The variable <code>CFLAGS="-I"</code> indicates where the compiler finds the header files.</li>
<li>The variable <code>LDFLAGS="-L"</code> indicates where the linker finds the libraries.</li>
<li>This <code>../wget-1.15</code> is the directory where wget source code is available. In this case, it is the same of <code>${HOME}/wget/wget-1.15</code>.</li>
<li>The option <code>--host=powerpc64le-linux</code> indicates this code runs on POWER little endian.</li>
<li>The option <code>--with-ssl=openssl</code> forces wget to use <code>OpenSSL</code>.</li>
</ul>
<p>Finally, build wget by using the make command:</p>
<code>make</code>
<p>After you run this command, you'll find the program available at <code>${HOME}/wget/build/src/wget</code>.</p>
<p>You can now copy it to a POWER little endian system with the Advance Toolchain runtime package installed and run it.</p>
</div>
<div class="ibm-col-12-12" style="background: #000;"></div>
</div>
<div class="ibm-band-fluid ibm-flex ibm-nospacing ibm-flex--wrap">
<div class="ibm-col-12-3 ibm-padding-top-1">
<p class="ibm-h3" id="faq">Frequently asked questions (FAQ)</p>
</div>
<div class="ibm-col-12-9 ibm-padding-top-1">
<p class="ibm-h4">Get answers to some of the most frequently asked questions about working with the cross-compiler.</p>
<div class="ibm-show-hide" data-type="panel" data-widget="showhide">
<h2>Are cross-compiler builds slower?</h2>
<div class="ibm-container-body">
<p>Not necessarily. It depends on the code being built and the level of optimization in use.</p>
</div>
<h2>If I build a program by using a cross-compiler, will it be slower than by using a native toolchain?</h2>
<div class="ibm-container-body">
<p>No. There are some differences in the metadata of the binaries, but it runs at the same speed.</p>
</div>
<h2>My project doesn’t allow passing flags to the linker or to the compiler. How can I use extra libraries?</h2>
<div class="ibm-container-body">
<p>In this case, it isn’t possible to pass <code>-I</code> to the compiler or <code>-L</code> to linker and the only possible solution is to save the headers and libraries in one of the Advance Toolchain directories:</p>
<p>For POWER big endian (ppc or ppc64):</p>
<pre>
/opt/atX.X/ppc/usr/include
/opt/atX.X/ppc/usr/lib (32-bit libraries)
/opt/atX.X/ppc/usr/lib64 (64-bit libraries)
</pre>
<p>For POWER little endian (ppc64le):</p>
<pre>
/opt/atX.X/ppc64le/usr/include
/opt/atX.X/ppc64le/usr/lib64
</pre>
<p>Be careful to not override any Advance Toolchain files while you are copying the files.</p>
</div>
</div>
</div>
<script> function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}</script></div>