{"action":"created","issue":{"url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/issues/3","repository_url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32","labels_url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/issues/3/comments","events_url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/issues/3/events","html_url":"https://github.com/mcoquelin-stm32/afboot-stm32/pull/3","id":141415381,"number":3,"title":"Use ld instead of gcc for linking","user":{"login":"tpetazzoni","id":1089203,"avatar_url":"https://avatars.githubusercontent.com/u/1089203?v=3","gravatar_id":"","url":"https://api.github.com/users/tpetazzoni","html_url":"https://github.com/tpetazzoni","followers_url":"https://api.github.com/users/tpetazzoni/followers","following_url":"https://api.github.com/users/tpetazzoni/following{/other_user}","gists_url":"https://api.github.com/users/tpetazzoni/gists{/gist_id}","starred_url":"https://api.github.com/users/tpetazzoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpetazzoni/subscriptions","organizations_url":"https://api.github.com/users/tpetazzoni/orgs","repos_url":"https://api.github.com/users/tpetazzoni/repos","events_url":"https://api.github.com/users/tpetazzoni/events{/privacy}","received_events_url":"https://api.github.com/users/tpetazzoni/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-16T22:02:35Z","updated_at":"2016-03-17T16:10:18Z","closed_at":"2016-03-17T16:09:26Z","pull_request":{"url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/pulls/3","html_url":"https://github.com/mcoquelin-stm32/afboot-stm32/pull/3","diff_url":"https://github.com/mcoquelin-stm32/afboot-stm32/pull/3.diff","patch_url":"https://github.com/mcoquelin-stm32/afboot-stm32/pull/3.patch"},"body":"Using gcc for linking is indeed normally the right choice. It works\r\nfine when using a bare metal arm-none-eabi toolchain.\r\n\r\nHowever, in build systems like Buildroot, we don't have two separate\r\ntoolchains, one bare-metal to build bootloader(s) and the kernel, and\r\none targetting Linux to build userspace libraries/binaries. We use a\r\nsingle toolchain targetting Linux, which is normally perfectly capable\r\nof building bare-metal code (U-Boot, Barebox, Linux kernel).\r\n\r\nUnfortunately, afboot-stm32 doesn't link properly with a Linux FLAT\r\ntoolchain, with the following error:\r\n\r\narm-buildroot-uclinux-uclibcgnueabi-gcc -T stm32f429.lds -nostartfiles -Wl,--gc-sections -o stm32f429i-disco.elf stm32f429i-disco.o gpio.o mpu.o usart-f4.o\r\nERROR: text=0x454 overlaps data=0x8000000 ?\r\n\r\nThis is due to gcc trying to generate a FLAT binary, rather than an\r\nELF file as expected by the afboot-stm32 build process. Since there is\r\napparently no flag to tell gcc to not produce a FLAT binary, the only\r\noption is to directly call ld.\r\n\r\nThis problem was reproduced using both a Cortex-M4 toolchain built by\r\nBuildroot, or a pre-built Cortex-M3 toolchain provided by OSELAS\r\ntoolchains.\r\n\r\nIn addition to using 'ld' directly instead of 'gcc', we rename LDFLAGS\r\nto LINKERFLAGS to make it clear that those flags are directly flags\r\nfor the linker (while LDFLAGS, contrary to what its name suggests, are\r\nflags for gcc when called for the link step).\r\n\r\nSigned-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>"},"comment":{"url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/issues/comments/197951794","html_url":"https://github.com/mcoquelin-stm32/afboot-stm32/pull/3#issuecomment-197951794","issue_url":"https://api.github.com/repos/mcoquelin-stm32/afboot-stm32/issues/3","id":197951794,"user":{"login":"mcoquelin-stm32","id":11241992,"avatar_url":"https://avatars.githubusercontent.com/u/11241992?v=3","gravatar_id":"","url":"https://api.github.com/users/mcoquelin-stm32","html_url":"https://github.com/mcoquelin-stm32","followers_url":"https://api.github.com/users/mcoquelin-stm32/followers","following_url":"https://api.github.com/users/mcoquelin-stm32/following{/other_user}","gists_url":"https://api.github.com/users/mcoquelin-stm32/gists{/gist_id}","starred_url":"https://api.github.com/users/mcoquelin-stm32/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcoquelin-stm32/subscriptions","organizations_url":"https://api.github.com/users/mcoquelin-stm32/orgs","repos_url":"https://api.github.com/users/mcoquelin-stm32/repos","events_url":"https://api.github.com/users/mcoquelin-stm32/events{/privacy}","received_events_url":"https://api.github.com/users/mcoquelin-stm32/received_events","type":"User","site_admin":false},"created_at":"2016-03-17T16:10:18Z","updated_at":"2016-03-17T16:10:18Z","body":"Thanks Thomas!\r\n\r\nIt looks good to me.\r\nI will prepare a new tag so that you can integrate it in Buildroot.\r\n\r\nRegards,\r\nMaxime"}}