From 0e25ee2715fb1d8498e242b00ab6f8c07830f495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Wed, 27 Feb 2019 00:00:00 +0000 Subject: [PATCH] glibc: update to 6c99e37f6fb640a50a3113b2dbee5d5389843c1e Initializes the submodule. --- .gitmodules | 3 +++ README.adoc | 60 ++++++++++++++++++++++++++++++++++++++++++++++ build | 7 +++++- buildroot_override | 1 + submodules/glibc | 1 + 5 files changed, 71 insertions(+), 1 deletion(-) create mode 160000 submodules/glibc diff --git a/.gitmodules b/.gitmodules index 81b53da..54e7d09 100644 --- a/.gitmodules +++ b/.gitmodules @@ -27,3 +27,6 @@ [submodule "submodules/boot-wrapper-aarch64"] path = submodules/boot-wrapper-aarch64 url = git://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git +[submodule "submodules/glibc"] + path = submodules/glibc + url = https://github.com/cirosantilli/glibc diff --git a/README.adoc b/README.adoc index b865773..62d51ba 100644 --- a/README.adoc +++ b/README.adoc @@ -303,6 +303,66 @@ If you really want to develop semiconductors, your only choice is to join an uni While hacking QEMU, you will likely want to GDB step its source. That is trivial since QEMU is just another userland program like any other, but our setup has a shortcut to make it even more convenient, see: <>. +===== Your first glibc hack + +We use <>, and it is tracked as an unmodified submodule at link:submodules/glibc[], at the exact same version that Buildroot has it, which can be found at: link:https://github.com/buildroot/buildroot/blob/2018.05/package/glibc/glibc.mk#L13[package/glibc/glibc.mk]. Buildroot 2018.05 applies no patches. + +Let's hack up the `puts` function: + +.... +./build-buildroot -- glibc-reconfigure +.... + +with the patch: + +.... +diff --git a/libio/ioputs.c b/libio/ioputs.c +index 706b20b492..23185948f3 100644 +--- a/libio/ioputs.c ++++ b/libio/ioputs.c +@@ -38,8 +38,9 @@ _IO_puts (const char *str) + if ((_IO_vtable_offset (_IO_stdout) != 0 + || _IO_fwide (_IO_stdout, -1) == -1) + && _IO_sputn (_IO_stdout, str, len) == len ++ && _IO_sputn (_IO_stdout, " hacked", 7) == 7 + && _IO_putc_unlocked ('\n', _IO_stdout) != EOF) +- result = MIN (INT_MAX, len + 1); ++ result = MIN (INT_MAX, len + 1 + 7); + + _IO_release_lock (_IO_stdout); + return result; +.... + +And then: + +.... +./run --eval-after '/hello.out' +.... + +outputs: + +.... +hello hacked +.... + +Lol! + +We can also test our hacked glibc on <> with: + +.... +./run --userland hello +.... + +I just noticed that this is actually a good way to develop glibc for other archs. + +Note that for arch agnostic features that don't rely on bleeding kernel changes that you host doesn't yet have, you can develop glibc natively as explained at: + +* https://stackoverflow.com/questions/10412684/how-to-compile-my-own-glibc-c-standard-library-from-source-and-use-it/52454710#52454710 +* https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host/52454603#52454603 +* https://stackoverflow.com/questions/2856438/how-can-i-link-to-a-specific-glibc-version/52550158#52550158 more focus on symbol versioning, but no one knows how to do it, so I answered + +Tested on a30ed0f047523ff2368d421ee2cce0800682c44e + 1. + ==== About the QEMU Buildroot setup This is our reference setup, and the best supported one, use it unless you have good reason not to. diff --git a/build b/build index dca3954..4cc82da 100755 --- a/build +++ b/build @@ -107,7 +107,12 @@ so looping over all of them would waste time. ) buildroot_component = _Component( self._build_file('build-buildroot'), - submodules = {'buildroot'}, + submodules = { + 'buildroot', + }, + submodules_shallow = { + 'glibc', + }, # https://buildroot.org/downloads/manual/manual.html#requirement apt_get_pkgs={ 'bash', diff --git a/buildroot_override b/buildroot_override index 4d3731a..57f5a10 100644 --- a/buildroot_override +++ b/buildroot_override @@ -1,2 +1,3 @@ LINUX_OVERRIDE_SRCDIR = ../../submodules/linux QEMU_OVERRIDE_SRCDIR = ../../submodules/qemu +GLIBC_OVERRIDE_SRCDIR = ../../submodules/glibc diff --git a/submodules/glibc b/submodules/glibc new file mode 160000 index 0000000..6c99e37 --- /dev/null +++ b/submodules/glibc @@ -0,0 +1 @@ +Subproject commit 6c99e37f6fb640a50a3113b2dbee5d5389843c1e