aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-multilib-config.inc
diff options
context:
space:
mode:
authorConstantin Musca <constantinx.musca@intel.com>2012-12-17 13:46:20 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-02-01 15:53:30 +0000
commitb26819c85881e82ee1b5c68840011e78c321f18e (patch)
treea6bbe3e2c86cc3da644f76d1c0d36f7fb224f294 /meta/recipes-devtools/gcc/gcc-multilib-config.inc
parent0e0a5ee405bab478f35690e95219a1e5f2ac7aa6 (diff)
downloadopenembedded-core-contrib-b26819c85881e82ee1b5c68840011e78c321f18e.tar.gz
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] Signed-off-by: Constantin Musca <constantinx.musca@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com>
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-multilib-config.inc')
-rw-r--r--meta/recipes-devtools/gcc/gcc-multilib-config.inc190
1 files changed, 190 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-multilib-config.inc b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
new file mode 100644
index 0000000000..9403aab0bd
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
@@ -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"