{"action":"created","issue":{"url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/issues/119","labels_url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/issues/119/comments","events_url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/issues/119/events","html_url":"https://github.com/crosstool-ng/crosstool-ng/pull/119","id":87819919,"number":119,"title":"32-bit multilib support for gcc and glibc","user":{"login":"trisk","id":207920,"avatar_url":"https://avatars.githubusercontent.com/u/207920?v=3","gravatar_id":"","url":"https://api.github.com/users/trisk","html_url":"https://github.com/trisk","followers_url":"https://api.github.com/users/trisk/followers","following_url":"https://api.github.com/users/trisk/following{/other_user}","gists_url":"https://api.github.com/users/trisk/gists{/gist_id}","starred_url":"https://api.github.com/users/trisk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trisk/subscriptions","organizations_url":"https://api.github.com/users/trisk/orgs","repos_url":"https://api.github.com/users/trisk/repos","events_url":"https://api.github.com/users/trisk/events{/privacy}","received_events_url":"https://api.github.com/users/trisk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-06-12T18:56:17Z","updated_at":"2015-06-17T20:49:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/pulls/119","html_url":"https://github.com/crosstool-ng/crosstool-ng/pull/119","diff_url":"https://github.com/crosstool-ng/crosstool-ng/pull/119.diff","patch_url":"https://github.com/crosstool-ng/crosstool-ng/pull/119.patch"},"body":"Quoting the email I'm drafting to the ct-ng list:\r\nI've encountered a series of problems after enabling multilib support with CT_MULTILIB=y using gcc and glibc on amd64. These may also affect non-x86 64-bit targets with a 32-bit multilib target.\r\n\r\nWhen multilib support is enabled, --host=${CT_TARGET} is still blindly passed to glibc's configure, although ${extra_cflags} is set. This causes multilib builds to fail when the primary target is amd64 and ${extra_cflags} is -m32. To solve this, we need to derive a target tuple for i586 or i686 (glibc 2.21 does not support a i386 target) and pass it with --host when ${extra_cflags} contains -m32. I introduced a new CT_TARGET_32 in CT_DoBuildTargetTuple, used in conjunction with -m32 by scripts/build/libc/glibc.sh (a similar entry for -m64 may be useful).\r\n\r\nThe second problem encountered is that pass 2 gcc's -m32 libgcc_s requires a stub libc.so installed with libc_startfiles, but all copies of libc.so are built identically without -m32. This is because the multilib ${extra_cflags} aren't being passed for their compilation. I fixed the parameters to be consistent with those used in CC when configuring glibc.\r\n\r\nThe third problem is that script/build/libc/glibc.sh's do_libc_backend installs a symlink to the location of the stub and startfiles to usr/lib/${multi_dir} on the assumption that \"gcc expects them in {,usr/}lib/${extra_dir}\", while the pass 2 gcc build on Linux/amd64 actually searches usr/lib32 and not /usr/lib/32 when -m32 is used. This is because for Linux/amd64, gcc/config/i386/t-linux64 specifies \"m32=../lib32\", etc. in MULTILIB_OSDIRNAMES for the available multilib options.\r\n\r\nIn ct-ng, usr/lib32 and usr/lib64 are both symlinks to usr/lib created by scripts/crosstool-NG.sh with this explanation: \"we're *not* multilib on the target side\". This assumption appears to be broken by enabling CT_MULTILIB. Either MULTILIB_OSDIRNAMES or the usr/lib32 symlink has to be altered to satisify libgcc_s linking. MULTILIB_OSDIRNAMES has variety of platform-specific configurations, so there are potentially bad side effects from overriding it globally globally, and extra work if patching each affected platform configuration file. Pointing the usr/lib{32,64} symlink corresponding to the multilib target to usr/lib/{32,64}, respectively, may be preferable for this case. For a 64-bit primary target I leave usr/lib64 symlinked to lib, as glibc still */lib64 install and runtime paths.\r\n\r\nThe final problem is the missing gnu/stubs-32.h and gnu/lib-names-32.h headers while building the final compiler, despite a multilib install of glibc. The initial gnu/stubs.h is an empty file created by scripts/build/libc/glibc.sh, but it is populated by the final glibc install, which also installs gnu/stubs-64.h. The multilib build of glibc installs the headers under ${CT_SYSROOT_DIR}/${multi_dir} which is subsequently deleted. The solution is to copy ${CT_SYSROOT_DIR}/${multi_dir}/usr/include/gnu/*-{multi_dir}.h to ${CT_HEADERS_DIR} before the deletion.\r\n\r\nThese changes produce a gcc/glibc toolchain capable of successfully compiling and linking programs with -m32.\r\n\r\n-Albert"},"comment":{"url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/issues/comments/112946067","html_url":"https://github.com/crosstool-ng/crosstool-ng/pull/119#issuecomment-112946067","issue_url":"https://api.github.com/repos/crosstool-ng/crosstool-ng/issues/119","id":112946067,"user":{"login":"trisk","id":207920,"avatar_url":"https://avatars.githubusercontent.com/u/207920?v=3","gravatar_id":"","url":"https://api.github.com/users/trisk","html_url":"https://github.com/trisk","followers_url":"https://api.github.com/users/trisk/followers","following_url":"https://api.github.com/users/trisk/following{/other_user}","gists_url":"https://api.github.com/users/trisk/gists{/gist_id}","starred_url":"https://api.github.com/users/trisk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trisk/subscriptions","organizations_url":"https://api.github.com/users/trisk/orgs","repos_url":"https://api.github.com/users/trisk/repos","events_url":"https://api.github.com/users/trisk/events{/privacy}","received_events_url":"https://api.github.com/users/trisk/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T20:49:06Z","updated_at":"2015-06-17T20:49:06Z","body":"Can you confirm if my comment about ${CT_SYSROOT_DIR}/${multi_dir}/usr/include is correct?"}}