uninative: call patchelf-uninative only when needed
PATCH 1/1 uninative: call patchelf-uninative only when needed
mke2fs.real, mkfs.ext2.real, mkfs.ext3.real, mkfs.ext4.real are indentical binary with multiple hardlinks and we end calling patchelf-uninative 4 times even when the interpreter is already set correctly from the build
To avoid corrupted binaries created by patchelf-0.18.0 when set-interpreter is called multiple times (on some systems like ubuntu-18.04 this leads to segfaults elsewhere just ldd complains that the executable is no longer dynamically linked, but doesn't fail when executed).
The issue was reported upstream with mkfs.ext4.real as possible reproducer:
https://github.com/NixOS/patchelf/issues/492#issuecomment-1602862272
alternatively we can revert
https://github.com/NixOS/patchelf/commit/65cdee904431d16668f95d816a495bc35a05a192
and create new uninative release with update patchelf-uninative, but better to wait a bit for upstream to have a look and possibly backport proper fix later, until then this change fixes the mkfs.ext4 issues I was seeing in kirkstone, mickledore, nanbield since uninative-3.9 upgrade, as reported in:
https://lists.openembedded.org/g/openembedded-core/message/182862
--- meta/classes-global/uninative.bbclass | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
meta/classes-global/uninative.bbclass +8 -3
@@ -175,7 +175,12 @@ python uninative_changeinterp () { if not elf.isDynamic(): continue - os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) - subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT) - os.chmod(f, s[stat.ST_MODE]) + current = subprocess.check_output(("patchelf-uninative", "--print-interpreter", f), stderr=subprocess.STDOUT).decode('utf-8').split('\n')[0] + if current != d.getVar("UNINATIVE_LOADER"): + bb.debug(2, "Changing interpreter from %s to %s with %s" % (current, d.getVar("UNINATIVE_LOADER"), ("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f))) + os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) + subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT) + os.chmod(f, s[stat.ST_MODE]) + else: + bb.debug(2, "Interpreter was already set to %s in %s" % (d.getVar("UNINATIVE_LOADER"), f)) }
Signature · 1 line
2.41.0
Quoted 35 lines · Martin Jansa
mke2fs.real, mkfs.ext2.real, mkfs.ext3.real, mkfs.ext4.real are indentical binary with multiple hardlinks and we end calling patchelf-uninative 4 times even when the interpreter is already set correctly from the build
To avoid corrupted binaries created by patchelf-0.18.0 when set-interpreter is called multiple times (on some systems like ubuntu-18.04 this leads to segfaults elsewhere just ldd complains that the executable is no longer dynamically linked, but doesn't fail when executed).
The issue was reported upstream with mkfs.ext4.real as possible reproducer:
https://github.com/NixOS/patchelf/issues/492#issuecomment-1602862272
alternatively we can revert
https://github.com/NixOS/patchelf/commit/65cdee904431d16668f95d816a495bc35a05a192
and create new uninative release with update patchelf-uninative, but better to wait a bit for upstream to have a look and possibly backport proper fix later, until then this change fixes the mkfs.ext4 issues I was seeing in kirkstone, mickledore, nanbield since uninative-3.9 upgrade, as reported in:
https://lists.openembedded.org/g/openembedded-core/message/182862Signed-off-by Martin Jansa <[email protected]>--- meta/classes-global/uninative.bbclass | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)meta/classes-global/uninative.bbclass +0
-2@@ -175,7 +175,12 @@ python uninative_changeinterp () { if not elf.isDynamic(): continue - os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) - subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)
meta/classes-global/uninative.bbclass python uninative_changeinterp () { · line 186
Quoted 10 lines
meta/classes-global/uninative.bbclass +8
-1- os.chmod(f, s[stat.ST_MODE]) + current = subprocess.check_output(("patchelf-uninative", "--print-interpreter", f), stderr=subprocess.STDOUT).decode('utf-8').split('\n')[0] + if current != d.getVar("UNINATIVE_LOADER"): + bb.debug(2, "Changing interpreter from %s to %s with %s" % (current, d.getVar("UNINATIVE_LOADER"), ("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f))) + os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) + subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT) + os.chmod(f, s[stat.ST_MODE]) + else: + bb.debug(2, "Interpreter was already set to %s in %s" % (d.getVar("UNINATIVE_LOADER"), f)) }
I know why you've done it this way but ideally we should make patchelf handle this internally? It would be nice to avoid fork calls if we can in the long run.
Cheers,
Richard
Quoted 58 lines · Richard Purdie
Quoted 1 line · Martin Jansa
mke2fs.real, mkfs.ext2.real, mkfs.ext3.real, mkfs.ext4.real are
indentical
Quoted 4 lines
binary with multiple hardlinks and we end calling patchelf-uninative 4 times even when the interpreter is already set correctly from the build
To avoid corrupted binaries created by patchelf-0.18.0 when
set-interpreter
Quoted 5 lines
is called multiple times (on some systems like ubuntu-18.04 this leads to segfaults elsewhere just ldd complains that the executable is no longer dynamically linked, but doesn't fail when executed).
The issue was reported upstream with mkfs.ext4.real as possible
reproducer:
Quoted 3 lines
https://github.com/NixOS/patchelf/issues/492#issuecomment-1602862272
alternatively we can reverthttps://github.com/NixOS/patchelf/commit/65cdee904431d16668f95d816a495bc35a05a192
Quoted 7 lines
and create new uninative release with update patchelf-uninative, but better to wait a bit for upstream to have a look and possibly backport proper fix later, until then this change fixes the mkfs.ext4 issues I was seeing in kirkstone, mickledore, nanbield since uninative-3.9 upgrade, as reported in:
https://lists.openembedded.org/g/openembedded-core/message/182862Review
Quoted 6 lines
Signed-off-by Martin Jansa <[email protected]>--- meta/classes-global/uninative.bbclass | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)(quoted diff) +0
-0b/meta/classes-global/uninative.bbclass
meta/classes-global/uninative.bbclass python uninative_changeinterp () { · line 179
Quoted 9 lines
index
366f7ac793..b54acdd542100644meta/classes-global/uninative.bbclass +0
-2@@ -175,7 +175,12 @@ python uninative_changeinterp () { if not elf.isDynamic(): continue - os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) - subprocess.check_output(("patchelf-uninative","--set-interpreter",
d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)meta/classes-global/uninative.bbclass python uninative_changeinterp () { · line 178
Quoted 2 lines
meta/classes-global/uninative.bbclass +1
-1- os.chmod(f, s[stat.ST_MODE]) + current = subprocess.check_output(("patchelf-uninative","--print-interpreter", f), stderr=subprocess.STDOUT).decode('utf-8').split('\n')[0]
meta/classes-global/uninative.bbclass python uninative_changeinterp () { · line 180
Quoted 2 lines
meta/classes-global/uninative.bbclass +2
-0+ if current != d.getVar("UNINATIVE_LOADER"): + bb.debug(2, "Changing interpreter from %s to %s with%s" % (current,
d.getVar("UNINATIVE_LOADER"), ("patchelf-uninative", "--set-interpreter",d.getVar("UNINATIVE_LOADER"), f)))meta/classes-global/uninative.bbclass python uninative_changeinterp () { · line 182
Quoted 2 lines
meta/classes-global/uninative.bbclass +2
-0+ os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) + subprocess.check_output(("patchelf-uninative","--set-interpreter",
d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)meta/classes-global/uninative.bbclass python uninative_changeinterp () {
Quoted 3 lines
meta/classes-global/uninative.bbclass +3
-0+ os.chmod(f, s[stat.ST_MODE]) + else: + bb.debug(2, "Interpreter was already set to %s in %s" %
Quoted 7 lines
(
d.getVar("UNINATIVE_LOADER"), f))meta/classes-global/uninative.bbclass python uninative_changeinterp () { · line 186
Quoted 1 line
meta/classes-global/uninative.bbclass +0
-0}I know why you've done it this way but ideally we should make patchelf handle this internally? It would be nice to avoid fork calls if we can in the long run.
yes, but that would require new uninative tarball to be built and applied in master, mickledore, kirkstone, dunfell, so I was waiting for feedback from upstream first before changing patchelf and using this as work around to be able to use uninative 3.9 and 4.0 until patchelf is fixed properly.