gcc: enable multilib for target gcc
- add a task to setup multilib configuration for target gcc - this commit adapts Nitin Kamble's work to gcc 4.7 - use a hash for storing arch-dependent multilib options - patch gcc in order to use the multilib config files from the build directory Tests: root@qemux86-64:~# gcc -m64 t.c -o t root@qemux86-64:~# file t t: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped root@qemux86-64:~# ./t Hello World ! root@qemux86-64:~# gcc -m32 t.c -o t root@qemux86-64:~# file t t: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped root@qemux86-64:~# ./t Hello World ! [YOCTO #1369] (From OE-Core rev: b26819c85881e82ee1b5c68840011e78c321f18e) Signed-off-by: Constantin Musca <constantinx.musca@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
62285873e2
commit
703b70c98a
|
@ -1,6 +1,6 @@
|
|||
require gcc-common.inc
|
||||
|
||||
PR = "r14"
|
||||
PR = "r15"
|
||||
|
||||
# Third digit in PV should be incremented after a minor release
|
||||
# happens from this branch on gcc e.g. currently its 4.7.1
|
||||
|
@ -74,6 +74,7 @@ SRC_URI = "${GNU_MIRROR}/gcc/gcc-${PV}/gcc-${PV}.tar.bz2 \
|
|||
file://ppc_no_crtsavres.patch \
|
||||
file://0001-crtstuff.c-USE_PT_GNU_EH_FRAME-Define-for-systems-us.patch \
|
||||
file://0001-Makefile.in-vis_hide-gen-hide-list-Do-not-make-defin.patch \
|
||||
file://use-ml-conf-files-from-B.patch \
|
||||
"
|
||||
SRC_URI[md5sum] = "cc308a0891e778cfda7a151ab8a6e762"
|
||||
SRC_URI[sha256sum] = "8a9283d7010fb9fe5ece3ca507e0af5c19412626384f8a5e9434251ae100b084"
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
Use the multilib config files from ${B} instead of using the ones from ${S}
|
||||
so that the source can be shared between gcc-cross-initial,
|
||||
gcc-cross-intermediate, gcc-cross, gcc-runtime, and also the sdk build.
|
||||
|
||||
Upstream-Status: Inappropriate [configuration]
|
||||
Signed-off-by: Constantin Musca <constantinx.musca@intel.com>
|
||||
|
||||
Index: gcc-4.7.2/gcc/configure
|
||||
===================================================================
|
||||
--- gcc-4.7.2.orig/gcc/configure
|
||||
+++ gcc-4.7.2/gcc/configure
|
||||
@@ -11717,10 +11717,20 @@ done
|
||||
tmake_file_=
|
||||
for f in ${tmake_file}
|
||||
do
|
||||
- if test -f ${srcdir}/config/$f
|
||||
- then
|
||||
- tmake_file_="${tmake_file_} \$(srcdir)/config/$f"
|
||||
- fi
|
||||
+ case $f in
|
||||
+ */t-linux64 )
|
||||
+ if test -f ./config/$f
|
||||
+ then
|
||||
+ tmake_file_="${tmake_file_} ./config/$f"
|
||||
+ fi
|
||||
+ ;;
|
||||
+ * )
|
||||
+ if test -f ${srcdir}/config/$f
|
||||
+ then
|
||||
+ tmake_file_="${tmake_file_} \$(srcdir)/config/$f"
|
||||
+ fi
|
||||
+ ;;
|
||||
+ esac
|
||||
done
|
||||
tmake_file="${tmake_file_}"
|
||||
|
||||
@@ -11731,6 +11741,10 @@ tm_file_list="options.h"
|
||||
tm_include_list="options.h insn-constants.h"
|
||||
for f in $tm_file; do
|
||||
case $f in
|
||||
+ */linux64.h )
|
||||
+ tm_file_list="${tm_file_list} ./config/$f"
|
||||
+ tm_include_list="${tm_include_list} ./config/$f"
|
||||
+ ;;
|
||||
./* )
|
||||
f=`echo $f | sed 's/^..//'`
|
||||
tm_file_list="${tm_file_list} $f"
|
||||
Index: gcc-4.7.2/gcc/configure.ac
|
||||
===================================================================
|
||||
--- gcc-4.7.2.orig/gcc/configure.ac
|
||||
+++ gcc-4.7.2/gcc/configure.ac
|
||||
@@ -1701,10 +1701,20 @@ done
|
||||
tmake_file_=
|
||||
for f in ${tmake_file}
|
||||
do
|
||||
- if test -f ${srcdir}/config/$f
|
||||
- then
|
||||
- tmake_file_="${tmake_file_} \$(srcdir)/config/$f"
|
||||
- fi
|
||||
+ case $f in
|
||||
+ */t-linux64 )
|
||||
+ if test -f ./config/$f
|
||||
+ then
|
||||
+ tmake_file_="${tmake_file_} ./config/$f"
|
||||
+ fi
|
||||
+ ;;
|
||||
+ * )
|
||||
+ if test -f ${srcdir}/config/$f
|
||||
+ then
|
||||
+ tmake_file_="${tmake_file_} \$(srcdir)/config/$f"
|
||||
+ fi
|
||||
+ ;;
|
||||
+ esac
|
||||
done
|
||||
tmake_file="${tmake_file_}"
|
||||
|
||||
@@ -1715,6 +1725,10 @@ tm_file_list="options.h"
|
||||
tm_include_list="options.h insn-constants.h"
|
||||
for f in $tm_file; do
|
||||
case $f in
|
||||
+ */linux64.h )
|
||||
+ tm_file_list="${tm_file_list} ./config/$f"
|
||||
+ tm_include_list="${tm_include_list} ./config/$f"
|
||||
+ ;;
|
||||
./* )
|
||||
f=`echo $f | sed 's/^..//'`
|
||||
tm_file_list="${tm_file_list} $f"
|
|
@ -34,6 +34,30 @@ def get_gcc_multiarch_setting(bb, d):
|
|||
return multiarch_options[target_arch]
|
||||
return ""
|
||||
|
||||
# this is used by the multilib setup of gcc
|
||||
def get_tune_parameters(tune, d):
|
||||
availtunes = d.getVar('AVAILTUNES', True)
|
||||
if tune not in availtunes.split():
|
||||
bb.error('The tune: %s is not one of the available tunes: %s', tune, availtunes)
|
||||
|
||||
localdata = bb.data.createCopy(d)
|
||||
override = ':tune-' + tune
|
||||
localdata.setVar('OVERRIDES', localdata.getVar('OVERRIDES', False) + override)
|
||||
bb.data.update_data(localdata)
|
||||
|
||||
retdict = {}
|
||||
retdict['tune'] = tune
|
||||
retdict['ccargs'] = localdata.getVar('TUNE_CCARGS', True)
|
||||
retdict['features'] = localdata.getVar('TUNE_FEATURES', True)
|
||||
# BASELIB is used by the multilib code to change library paths
|
||||
retdict['baselib'] = localdata.getVar('BASE_LIB', True) or localdata.getVar('BASELIB', True)
|
||||
retdict['arch'] = localdata.getVar('TUNE_ARCH', True)
|
||||
retdict['abiextension'] = localdata.getVar('ABIEXTENSION', True)
|
||||
retdict['target_fpu'] = localdata.getVar('TARGET_FPU', True)
|
||||
retdict['pkgarch'] = localdata.getVar('TUNE_PKGARCH', True)
|
||||
retdict['package_extra_archs'] = localdata.getVar('PACKAGE_EXTRA_ARCHS', True)
|
||||
return retdict
|
||||
|
||||
# We really need HOST_SYS here for some packages and TARGET_SYS for others.
|
||||
# For now, libgcc is most important so we fix for that - RP.
|
||||
SHLIBSDIR = "${STAGING_DIR_TARGET}/shlibs"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require gcc-multilib-config.inc
|
||||
#
|
||||
# Build the list of lanaguages to build.
|
||||
#
|
||||
|
@ -25,7 +26,7 @@ EXTRA_OECONF_PATHS ?= ""
|
|||
EXTRA_OECONF_INITIAL ?= ""
|
||||
EXTRA_OECONF_INTERMEDIATE ?= ""
|
||||
|
||||
GCCMULTILIB = "--disable-multilib"
|
||||
GCCMULTILIB ?= "--disable-multilib"
|
||||
GCCTHREADS ?= "posix"
|
||||
|
||||
EXTRA_OECONF = "${@['--enable-clocale=generic', ''][d.getVar('USE_NLS', True) != 'no']} \
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
GCCMULTILIB = "--enable-multilib"
|
||||
require gcc-configure-common.inc
|
||||
|
||||
EXTRA_OECONF_PATHS = " \
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
# following code modifies these definitions in the gcc config
|
||||
# MULTILIB_OPTIONS
|
||||
# MULTILIB_DIRNAMES
|
||||
# MULTILIB_OSDIRNAMES
|
||||
# GLIBC_DYNAMIC_LINKER32
|
||||
# GLIBC_DYNAMIC_LINKER64
|
||||
# GLIBC_DYNAMIC_LINKERX32
|
||||
# GLIBC_DYNAMIC_LINKERN32
|
||||
# For more information on use of these variables look at these files in the gcc source code
|
||||
# gcc/config/i386/t-linux64
|
||||
# gcc/config/mips/t-linux64
|
||||
# gcc/config/rs6000/t-linux64
|
||||
# gcc/config/i386/linux64.h
|
||||
# gcc/config/mips/linux64.h
|
||||
# gcc/config/rs6000/linux64.h
|
||||
|
||||
python gcc_multilib_setup() {
|
||||
import re
|
||||
import shutil
|
||||
import glob
|
||||
|
||||
srcdir = d.getVar('S', True)
|
||||
builddir = d.getVar('B', True)
|
||||
src_conf_dir = '%s/gcc/config' % srcdir
|
||||
build_conf_dir = '%s/gcc/config' % builddir
|
||||
|
||||
bb.utils.remove(build_conf_dir, True)
|
||||
ml_globs = ('%s/*/t-linux64' % src_conf_dir,
|
||||
'%s/*/linux64.h' % src_conf_dir)
|
||||
|
||||
# copy the target multilib config files to ${B}
|
||||
for ml_glob in ml_globs:
|
||||
for fn in glob.glob(ml_glob):
|
||||
rel_path = os.path.relpath(fn, src_conf_dir)
|
||||
parent_dir = os.path.dirname(rel_path)
|
||||
bb.utils.mkdirhier('%s/%s' % (build_conf_dir, parent_dir))
|
||||
bb.copyfile(fn, '%s/%s' % (build_conf_dir, rel_path))
|
||||
|
||||
multilibs = (d.getVar('MULTILIB_VARIANTS', True) or '').split()
|
||||
if not multilibs:
|
||||
return
|
||||
|
||||
mlprefix = d.getVar('MLPREFIX', True)
|
||||
if ('%sgcc' % mlprefix) != d.getVar('PN', True):
|
||||
return
|
||||
|
||||
|
||||
def write_config(root, files, options, dirnames, osdirnames):
|
||||
for ml_conf_file in files:
|
||||
with open(root + '/' + ml_conf_file, 'r') as f:
|
||||
filelines = f.readlines()
|
||||
# recreate multilib configuration variables
|
||||
substs = [
|
||||
(r'^(\s*(MULTILIB_OPTIONS\s*=).*)$', r'\2 %s' % '/'.join(options)),
|
||||
(r'^(\s*MULTILIB_OPTIONS\s*\+=.*)$', ''),
|
||||
(r'^(\s*(MULTILIB_DIRNAMES\s*=).*)$', r'\2 %s' % ' '.join(dirnames)),
|
||||
(r'^(\s*MULTILIB_DIRNAMES\s*\+=.*)$', ''),
|
||||
(r'^(\s*(MULTILIB_OSDIRNAMES\s*=).*)$', r'\2 %s' % ' '.join(osdirnames)),
|
||||
(r'^(\s*MULTILIB_OSDIRNAMES\s*\+=.*)$', ''),
|
||||
]
|
||||
|
||||
for (i, line) in enumerate(filelines):
|
||||
for subst in substs:
|
||||
line = re.sub(subst[0], subst[1], line)
|
||||
filelines[i] = line
|
||||
|
||||
with open(root + '/' + ml_conf_file, 'w') as f:
|
||||
f.write(''.join(filelines))
|
||||
|
||||
def write_headers(root, files, libdir32, libdir64, libdirx32, libdirn32):
|
||||
def wrap_libdir(libdir):
|
||||
if libdir.find('SYSTEMLIBS_DIR') != -1:
|
||||
return libdir
|
||||
else:
|
||||
return '"/%s/"' % libdir
|
||||
|
||||
for ml_conf_file in files:
|
||||
with open(root + '/' + ml_conf_file, 'r') as f:
|
||||
filelines = f.readlines()
|
||||
|
||||
# replace lines like
|
||||
# #define GLIBC_DYNAMIC_LINKER32 SYSTEMLIBS_DIR "ld-linux.so.2"
|
||||
# by
|
||||
# #define GLIBC_DYNAMIC_LINKER32 "/lib/" "ld-linux.so.2"
|
||||
# this is needed to put the correct dynamic loader path in the generated binaries
|
||||
substs = [
|
||||
(r'^(#define\s*GLIBC_DYNAMIC_LINKER32\s*)(\S+)(\s*\".*\")$',
|
||||
r'\1' + wrap_libdir(libdir32) + r'\3'),
|
||||
(r'^(#define\s*GLIBC_DYNAMIC_LINKER64\s*)(\S+)(\s*\".*\")$',
|
||||
r'\1' + wrap_libdir(libdir64) + r'\3'),
|
||||
(r'^(#define\s*GLIBC_DYNAMIC_LINKERX32\s*)(\S+)(\s*\".*\")$',
|
||||
r'\1' + wrap_libdir(libdirx32) + r'\3'),
|
||||
(r'^(#define\s*GLIBC_DYNAMIC_LINKERN32\s*)(\S+)(\s*\".*\")$',
|
||||
r'\1' + wrap_libdir(libdirn32) + r'\3'),
|
||||
]
|
||||
|
||||
for (i, line) in enumerate(filelines):
|
||||
for subst in substs:
|
||||
line = re.sub(subst[0], subst[1], line)
|
||||
filelines[i] = line
|
||||
|
||||
with open(root + '/' + ml_conf_file, 'w') as f:
|
||||
f.write(''.join(filelines))
|
||||
|
||||
|
||||
gcc_target_config_files = {
|
||||
'x86_64' : ['gcc/config/i386/t-linux64'],
|
||||
'i586' : ['gcc/config/i386/t-linux64'],
|
||||
'mips' : ['gcc/config/mips/t-linux64'],
|
||||
'powerpc' : ['gcc/config/rs6000/t-linux64'],
|
||||
}
|
||||
|
||||
gcc_header_config_files = {
|
||||
'x86_64' : ['gcc/config/i386/linux64.h'],
|
||||
'i586' : ['gcc/config/i386/linux64.h'],
|
||||
'mips' : ['gcc/config/mips/linux64.h'],
|
||||
'powerpc' : ['gcc/config/rs6000/linux64.h'],
|
||||
}
|
||||
|
||||
target_arch = (d.getVar('TARGET_ARCH_MULTILIB_ORIGINAL', True) if mlprefix
|
||||
else d.getVar('TARGET_ARCH', True))
|
||||
if target_arch not in gcc_target_config_files:
|
||||
bb.warn('gcc multilib setup is not supported for TARGET_ARCH=' + target_arch)
|
||||
return
|
||||
|
||||
libdir32 = 'SYSTEMLIBS_DIR'
|
||||
libdir64 = 'SYSTEMLIBS_DIR'
|
||||
libdirx32 = 'SYSTEMLIBS_DIR'
|
||||
libdirn32 = 'SYSTEMLIBS_DIR'
|
||||
|
||||
target_config_files = gcc_target_config_files[target_arch]
|
||||
header_config_files = gcc_header_config_files[target_arch]
|
||||
|
||||
ml_list = ['DEFAULTTUNE_MULTILIB_ORIGINAL' if mlprefix else 'DEFAULTTUNE']
|
||||
mltunes = [('DEFAULTTUNE_virtclass-multilib-%s' % ml) for ml in multilibs]
|
||||
if mlprefix:
|
||||
mlindex = 0
|
||||
for ml in multilibs:
|
||||
if mlprefix.startswith(ml):
|
||||
break
|
||||
mlindex += 1
|
||||
|
||||
ml_list.extend(mltunes[:mlindex] + ['DEFAULTTUNE'] + mltunes[(mlindex + 1):])
|
||||
else:
|
||||
ml_list.extend(mltunes)
|
||||
|
||||
options = []
|
||||
dirnames = []
|
||||
osdirnames = []
|
||||
|
||||
for ml in ml_list:
|
||||
tune = d.getVar(ml, True)
|
||||
if not tune:
|
||||
bb.warn("%s doesn't have a corresponding tune. Skipping..." % ml)
|
||||
continue
|
||||
tune_parameters = get_tune_parameters(tune, d)
|
||||
|
||||
tune_baselib = tune_parameters['baselib']
|
||||
if not tune_baselib:
|
||||
bb.warn("Tune %s doesn't have a baselib set. Skipping..." % tune)
|
||||
continue
|
||||
|
||||
if tune_baselib == 'lib64':
|
||||
libdir64 = tune_baselib
|
||||
elif tune_baselib == 'libx32':
|
||||
libdirx32 = tune_baselib
|
||||
elif tune_baselib == 'lib32':
|
||||
libdirn32 = tune_baselib
|
||||
elif tune_baselib == 'lib':
|
||||
libdir32 = tune_baselib
|
||||
else:
|
||||
bb.error('Unknown libdir (%s) of the tune : %s' % (tune_baselib, tune))
|
||||
|
||||
# take out '-' and march='s from parameters
|
||||
options.append(re.sub(r'march=[^ ]+ *', '',
|
||||
re.sub(r' +\-+', ' ',
|
||||
re.sub(r'^ *\-+', '', tune_parameters['ccargs']))))
|
||||
if tune_baselib == 'lib':
|
||||
dirnames.append('32') # /lib => 32bit lib
|
||||
else:
|
||||
dirnames.append(tune_baselib.replace('lib', ''))
|
||||
osdirnames.append('../' + tune_baselib)
|
||||
|
||||
write_config(builddir, target_config_files, options, dirnames, osdirnames)
|
||||
write_headers(builddir, header_config_files, libdir32, libdir64, libdirx32, libdirn32)
|
||||
}
|
||||
|
||||
gcc_multilib_setup[cleandirs] = "${B}/gcc/config"
|
||||
|
||||
EXTRACONFFUNCS += "gcc_multilib_setup"
|
|
@ -15,6 +15,10 @@ FILES_${PN} = "${base_libdir}/libgcc*.so.*"
|
|||
FILES_${PN}-dev = " \
|
||||
${base_libdir}/libgcc*.so \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/*crt* \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/64 \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/32 \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/x32 \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/n32 \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/libgcc*"
|
||||
FILES_libgcov-dev = " \
|
||||
${libdir}/${TARGET_SYS}/${BINV}/libgcov.a \
|
||||
|
@ -70,3 +74,72 @@ BBCLASSEXTEND = "nativesdk"
|
|||
|
||||
INSANE_SKIP_${PN}-dev = "staticdev"
|
||||
INSANE_SKIP_${MLPREFIX}libgcov-dev = "staticdev"
|
||||
|
||||
addtask multilib_install after do_install before do_package do_populate_sysroot
|
||||
# this makes multilib gcc files findable for target gcc
|
||||
# e.g.
|
||||
# /usr/lib/i586-pokymllib32-linux/4.7/
|
||||
# by creating this symlink to it
|
||||
# /usr/lib64/x86_64-poky-linux/4.7/32
|
||||
|
||||
python do_multilib_install() {
|
||||
import re
|
||||
|
||||
multilibs = d.getVar('MULTILIB_VARIANTS', True)
|
||||
if not multilibs:
|
||||
return
|
||||
|
||||
binv = d.getVar('BINV', True)
|
||||
|
||||
mlprefix = d.getVar('MLPREFIX', True)
|
||||
if ('%slibgcc' % mlprefix) != d.getVar('PN', True):
|
||||
return
|
||||
|
||||
if mlprefix:
|
||||
orig_tune = d.getVar('DEFAULTTUNE_MULTILIB_ORIGINAL', True)
|
||||
orig_tune_params = get_tune_parameters(orig_tune, d)
|
||||
orig_tune_baselib = orig_tune_params['baselib']
|
||||
orig_tune_bitness = orig_tune_baselib.replace('lib', '')
|
||||
if not orig_tune_bitness:
|
||||
orig_tune_bitness = '32'
|
||||
|
||||
src = '../../../' + orig_tune_baselib + '/' + \
|
||||
d.getVar('TARGET_SYS_MULTILIB_ORIGINAL', True) + '/' + binv + '/'
|
||||
|
||||
dest = d.getVar('D', True) + d.getVar('libdir', True) + '/' + \
|
||||
d.getVar('TARGET_SYS', True) + '/' + binv + '/' + orig_tune_bitness
|
||||
|
||||
if os.path.lexists(dest):
|
||||
os.unlink(dest)
|
||||
os.symlink(src, dest)
|
||||
return
|
||||
|
||||
|
||||
for ml in multilibs.split():
|
||||
tune = d.getVar('DEFAULTTUNE_virtclass-multilib-' + ml, True)
|
||||
if not tune:
|
||||
bb.warn('DEFAULTTUNE_virtclass-multilib-%s is not defined. Skipping...' % ml)
|
||||
continue
|
||||
|
||||
tune_parameters = get_tune_parameters(tune, d)
|
||||
tune_baselib = tune_parameters['baselib']
|
||||
if not tune_baselib:
|
||||
bb.warn("Tune %s doesn't have a baselib set. Skipping..." % tune)
|
||||
continue
|
||||
|
||||
tune_arch = tune_parameters['arch']
|
||||
tune_bitness = tune_baselib.replace('lib', '')
|
||||
if not tune_bitness:
|
||||
tune_bitness = '32' # /lib => 32bit lib
|
||||
|
||||
src = '../../../' + tune_baselib + '/' + \
|
||||
tune_arch + d.getVar('TARGET_VENDOR', True) + 'ml' + ml + \
|
||||
'-' + d.getVar('TARGET_OS', True) + '/' + binv + '/'
|
||||
|
||||
dest = d.getVar('D', True) + d.getVar('libdir', True) + '/' + \
|
||||
d.getVar('TARGET_SYS', True) + '/' + binv + '/' + tune_bitness
|
||||
|
||||
if os.path.lexists(dest):
|
||||
os.unlink(dest)
|
||||
os.symlink(src, dest)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue