Bug 1289812

Summary: ld.so fails to load go binary when using LD_BIND_NOW=1
Product: [Fedora] Fedora Reporter: Carlos O'Donell <codonell>
Component: glibcAssignee: Carlos O'Donell <codonell>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 23CC: arjun.is, codonell, fweimer, jakub, law, mfabian, pfrankli, siddhesh
Target Milestone: ---Keywords: Patch
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: glibc-2.23 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-24 14:34:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Carlos O'Donell 2015-12-09 02:24:52 UTC
Create a go program that uses cgo to reference external API's like those core glibc API's which in turn use NSS. This causes the the go runtime to create a real dynamic binary, but this binary has a gap between .rela and .rela.plt, which F23's version of ld.so does not support.

cat >> print-user-home.go <<EOF
package main

import "fmt"
import "os/user"
import "log"

func main() {
    myself, err := user.Current()
    if (err != nil) {
        log.Fatal (err)
    }
    fmt.Println(myself.HomeDir)
}
EOF

go build print-user-home.go 

./print-user-home 
/home/carlos

ldd print-user-home
	linux-vdso.so.1 (0x00007ffdac7f4000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdf4f197000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fdf4edd6000)
	/lib64/ld-linux-x86-64.so.2 (0x0000555c63c7d000)

LD_BIND_NOW=1 ./print-user-home 
./print-user-home: error while loading shared libraries: unexpected reloc type 0x005a4018

This is upstream bug 14341, adding here for posterity, but without any real user reports we'll park it here for documentation purposes.

From fa19d5c48a6b36518ce68412e3bdde6bfa8aa4a6 Mon Sep 17 00:00:00 2001
From: Petar Jovanovic <petar.jovanovic>
Date: Wed, 20 Aug 2014 00:50:54 +0200
Subject: [PATCH] Fix dynamic linker issue with bind-now

Fix the bind-now case when DT_REL and DT_JMPREL sections are separate
and there is a gap between them.

	[BZ #14341]
	* elf/dynamic-link.h (elf_machine_lazy_rel): Properly handle the
	case when there is a gap between DT_REL and DT_JMPREL sections.
	* sysdeps/x86_64/Makefile (tests): Add tst-split-dynreloc.
	(LDFLAGS-tst-split-dynreloc): New.
	(tst-split-dynreloc-ENV): Likewise.
	* sysdeps/x86_64/tst-split-dynreloc.c: New file.
	* sysdeps/x86_64/tst-split-dynreloc.lds: Likewise.

Comment 1 Carlos O'Donell 2015-12-09 02:30:55 UTC
The code is question is generic, so marking "All" hardware.

Comment 2 Jakub Jelinek 2015-12-09 07:28:39 UTC
Why change glibc?  IMNSHO that is clearly a bug in the tool that generated the binary/library.

Comment 3 Florian Weimer 2015-12-09 09:28:00 UTC
(In reply to Jakub Jelinek from comment #2)
> Why change glibc?  IMNSHO that is clearly a bug in the tool that generated
> the binary/library.

There is a pre-existing comment in the glibc source code that this layout has to be supported:

/* On some machines, notably SPARC, DT_REL* includes DT_JMPREL in its
   range.  Note that according to the ELF spec, this is completely legal!

   We are guarenteed that we have one of three situations.  Either DT_JMPREL
   comes immediately after DT_REL*, or there is overlap and DT_JMPREL
   consumes precisely the very end of the DT_REL*, or DT_JMPREL and DT_REL*
   are completely separate and there is a gap between them.  */

Comment 4 Fedora End Of Life 2016-11-24 14:05:00 UTC
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '23'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 23 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 5 Florian Weimer 2016-11-24 14:34:07 UTC
This was fixed in Fedora 24.