commit a2131bf
Erik Tagirov
·
2026-04-12 17:38:32 +0000 UTC
parent 56277cc
binutils: aarch64 support Enable BFD and set gas target arch to aarch64, if building with aarch64-linux-musl
5 files changed,
+63,
-25
+5,
-1
1@@ -4,13 +4,17 @@
2 Generated with
3
4 ./configure \
5- --target=x86_64-linux-musl \
6+ --build=x86_64-unknown-linux-musl \
7 --disable-gold \
8 --disable-libctf \
9 --disable-nls \
10 --disable-plugins \
11+ --enable-compressed-debug-sections=gas \
12 --enable-default-hash-style=gnu \
13 --enable-deterministic-archives \
14 --enable-new-dtags \
15+ --enable-separate-code \
16+ --enable-textrel-check \
17+ --enable-x86-used-note \
18 --without-msgpack
19 make configure-host
+2,
-0
1@@ -2,7 +2,9 @@
2 # error config.h must be #included before system headers
3 #endif
4 #define __CONFIG_H__ 1
5+#ifdef __x86_64__
6 #define CORE_HEADER "hosts/x86-64linux.h"
7+#endif
8 #define DEFAULT_LD_Z_SEPARATE_CODE 1
9 /* #undef ENABLE_CHECKING */
10 /* #undef ENABLE_NLS */
+1,
-1
1@@ -64,7 +64,7 @@
2 #define SIZEOF_LONG 8
3 #define SIZEOF_LONG_LONG 8
4 #define STDC_HEADERS 1
5-#define TARGET "x86_64-pc-linux-musl"
6+/* #undef TARGET */
7 #define TARGET_PREPENDS_UNDERSCORE 0
8 #define TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC 1
9 /* #undef USE_BINARY_FOPEN */
+7,
-7
1@@ -6,9 +6,9 @@
2 /* #undef AIX_WEAK_SUPPORT */
3 /* #undef BROKEN_ASSERT */
4 /* #undef CROSS_COMPILE */
5-#define DEFAULT_ARCH "x86_64"
6+/* #undef DEFAULT_ARCH */
7 /* #undef DEFAULT_CRIS_ARCH */
8-#define DEFAULT_EMULATION "i386elf"
9+/* #undef DEFAULT_EMULATION */
10 #define DEFAULT_FLAG_COMPRESS_DEBUG 1
11 #define DEFAULT_GENERATE_BUILD_NOTES 0
12 #define DEFAULT_GENERATE_ELF_STT_COMMON 0
13@@ -19,7 +19,7 @@
14 /* #undef DEFAULT_RISCV_ISA_SPEC */
15 /* #undef DEFAULT_RISCV_PRIV_SPEC */
16 #define DEFAULT_X86_USED_NOTE 1
17-#define EMULATIONS &i386elf,
18+/* #undef EMULATIONS */
19 /* #undef ENABLE_CHECKING */
20 /* #undef ENABLE_NLS */
21 #define HAVE_DECL_ASPRINTF 1
22@@ -73,13 +73,13 @@
23 #define PACKAGE_VERSION "2.39"
24 #define STDC_HEADERS 1
25 /* #undef STRICTCOFF */
26-#define TARGET_ALIAS "x86_64-linux-musl"
27+/* #undef TARGET_ALIAS */
28 /* #undef TARGET_BYTES_BIG_ENDIAN */
29-#define TARGET_CANONICAL "x86_64-pc-linux-musl"
30-#define TARGET_CPU "x86_64"
31+/* #undef TARGET_CANONICAL */
32+/* #undef TARGET_CPU */
33 #define TARGET_OS "linux-musl"
34 /* #undef TARGET_SOLARIS_COMMENT */
35-#define TARGET_VENDOR "pc"
36+#define TARGET_VENDOR "unknown"
37 /* #undef TARGET_WITH_CPU */
38 /* #undef USE_BINARY_FOPEN */
39 /* #undef USE_EMULATIONS */
+48,
-16
1@@ -1,11 +1,26 @@
2-local version = setmetatable({2, 39}, {__index=function() return 0 end})
3-local defvec = 'x86_64_elf64_vec'
4-local selvecs = {[defvec]=true, i386_elf32_vec=true}
5-local selarchs = {i386=true}
6-local emuls = {
7- 'elf_x86_64',
8- 'elf_i386',
9+local targets = {
10+ -- when adding a new target, check that archs[1] matches gas cpu_type
11+ x86_64={
12+ vecs={'x86_64_elf64_vec', 'i386_elf32_vec'},
13+ archs={'i386'},
14+ emuls={'elf_x86_64', 'elf_i386'},
15+ },
16+ aarch64={
17+ vecs={'aarch64_elf64_le_vec'},
18+ archs={'aarch64'},
19+ emuls={'aarch64elf', 'aarch64linux', 'aarch64elfb'},
20+ }
21 }
22+local arch = config.target.platform:match('[^-]*')
23+local targ = targets[arch]
24+if not targ then
25+ return
26+end
27+
28+local version = setmetatable({2, 39}, {__index=function() return 0 end})
29+local emuls = targets[arch].emuls
30+local selarchs = {}
31+for _, a in pairs(targets[arch].archs) do selarchs[a] = true end
32
33 cflags{
34 '-std=c99', '-Wall', '-Wno-return-local-addr', '-Wno-stringop-truncation',
35@@ -87,9 +102,12 @@ sub('bfd.ninja', function()
36 build('sed', '$outdir/bfd/elf64-target.h', '$srcdir/bfd/elfxx-target.h', {expr='-e s,NN,64,g'})
37 build('sed', '$outdir/bfd/pex64igen.c', '$srcdir/bfd/peXXigen.c', {expr='-e s,XX,pex64,g'})
38 build('sed', '$outdir/bfd/peigen.c', '$srcdir/bfd/peXXigen.c', {expr='-e s,XX,pe,g'})
39+ build('sed', '$outdir/bfd/elf64-aarch64.c', '$srcdir/bfd/elfnn-aarch64.c', {expr='-e s,NN,64,g'})
40
41 -- src/bfd/config.bfd
42- for _, vec in ipairs(table.keys(selvecs)) do
43+ local selvecs = {}
44+ for _, vec in ipairs(targets[arch].vecs) do
45+ selvecs[vec] = true
46 if vec:find('elf64') or vec:find('mips_elf32_n') then
47 selvecs.elf64_le_vec = true
48 selvecs.elf64_be_vec = true
49@@ -107,6 +125,7 @@ sub('bfd.ninja', function()
50 ['dwarf2.c']='bfd/dwarf2.c.o',
51 ['peigen.c']='$outdir/bfd/peigen.c',
52 ['pex64igen.c']='$outdir/bfd/pex64igen.c',
53+ ['elf64-aarch64.c']='$outdir/bfd/elf64-aarch64.c',
54 }
55 for vec, vecsrcs in pairs(load 'vec.lua') do
56 if selvecs[vec] then
57@@ -127,7 +146,7 @@ sub('bfd.ninja', function()
58 local selvecnames = table.keys(selvecs)
59 cc('bfd/targets.c', nil, {cflags={
60 '$cflags',
61- '-D DEFAULT_VECTOR='..defvec,
62+ '-D DEFAULT_VECTOR='..selvecnames[1],
63 '-D HAVE_'..table.concat(selvecnames, ' -D HAVE_'),
64 string.format([[-D 'SELECT_VECS=&%s']], table.concat(selvecnames, ',&')),
65 }})
66@@ -176,6 +195,7 @@ end)
67 sub('binutils.ninja', function()
68 cflags{
69 string.format([[-D 'LOCALEDIR="%s/share/locale"']], config.prefix),
70+ string.format([[-D 'TARGET="%s-unknown-linux-musl"']], arch),
71 '-D bin_dummy_emulation=bin_vanilla_emulation',
72 '-I $dir/binutils',
73 '-I $srcdir/binutils',
74@@ -220,16 +240,24 @@ sub('binutils.ninja', function()
75 end)
76
77 sub('gas.ninja', function()
78+
79 cflags{
80 '-I $dir/gas',
81 '-I $outdir/gas',
82 '-I $srcdir/gas',
83 '-I $srcdir/gas/config',
84 '-I $srcdir',
85+ string.format([[-D 'DEFAULT_ARCH="%s"']], arch),
86+ string.format([[-D 'DEFAULT_EMULATION="%s"']], emuls[1]),
87+ string.format([[-D 'EMULATIONS=&%s,']], table.concat(emuls, ',&')),
88+ string.format([[-D 'TARGET_ALIAS="%s-linux-musl"']], arch),
89+ string.format([[-D 'TARGET_CANONICAL="%s-unknown-linux-musl"']], arch),
90+ string.format([[-D 'TARGET_CPU="%s"']], arch),
91 }
92- build('copy', '$outdir/gas/targ-cpu.h', '$srcdir/gas/config/tc-i386.h')
93+ build('copy', '$outdir/gas/targ-cpu.h', '$srcdir/gas/config/tc-'..targ.archs[1]..'.h')
94 build('copy', '$outdir/gas/targ-env.h', '$srcdir/gas/config/te-linux.h')
95 build('copy', '$outdir/gas/obj-format.h', '$srcdir/gas/config/obj-elf.h')
96+
97 local deps = {
98 '$gendir/deps',
99 '$outdir/gas/targ-cpu.h',
100@@ -237,7 +265,7 @@ sub('gas.ninja', function()
101 '$outdir/gas/obj-format.h',
102 }
103 -- src/gas/Makefile.am:/^GAS_CFILES
104- exe('bin/as', [[
105+ local srcs = paths[[
106 gas/(
107 app.c
108 as.c
109@@ -270,11 +298,15 @@ sub('gas.ninja', function()
110 symbols.c
111 write.c
112
113- config/(tc-i386.c obj-elf.c atof-ieee.c)
114+ config/(obj-elf.c atof-ieee.c)
115 )
116- libopcodes.a
117- libbfd.a.d
118- ]], deps)
119+ ]]
120+ exe('bin/as', {
121+ srcs,
122+ 'gas/config/tc-'..targ.archs[1]..'.c',
123+ 'libopcodes.a',
124+ 'libbfd.a.d',
125+ }, deps)
126 file('bin/as', '755', '$outdir/bin/as')
127 sym(string.format('bin/%s-as', config.target.platform), 'as')
128 man{'gas/doc/as.1'}
129@@ -314,7 +346,7 @@ sub('ld.ninja', function()
130 cc('ld/ldmain.c', nil, {cflags={
131 '$cflags',
132 string.format([[-D 'DEFAULT_EMULATION="%s"']], emuls[1]),
133- string.format([[-D 'TARGET="%s"']], 'x86_64-pc-linux-musl'),
134+ string.format([[-D 'TARGET="%s-unknown-linux-musl"']], arch)
135 }})
136 exe('bin/ld', {
137 -- src/ld/Makefile.am:/^ld_new_SOURCES