All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hajime Tazaki<thehajime@gmail.com>
To: johannes@sipsolutions.net
Cc: rrs@debian.org, anton.ivanov@kot-begemot.co.uk,
	chris.obbard@collabora.com, linux-um@lists.infradead.org,
	983379@bugs.debian.org
Subject: Re: linux uml segfault
Date: Sun, 07 Mar 2021 21:22:13 +0900	[thread overview]
Message-ID: <m2sg57jgqy.wl-thehajime@gmail.com> (raw)
In-Reply-To: <5fee882c709f6c9d061b58a0e7b3110b3afbb96e.camel@sipsolutions.net>


Sorry that this email is going to be long.  In summary, what Johannes
said is right: what objcopy does is not sufficient, and with ld it
transforms as we expected.

More goes to below.

On Sat, 06 Mar 2021 05:22:19 +0900,
Johannes Berg wrote:
> 
> On Thu, 2021-03-04 at 14:38 +0900, Hajime Tazaki wrote:
> > 
> > objcopy (from binutils) can localize symbols (i.e., objcopy -L
> > sem_init $orig_file $new_file).
> 
> This doesn't seem to be sufficient.
> 
> > It also does renaming symbols.  But
> > not sure this is the ideal solution.
> 
> Even that doesn't seem to actually work/help? I still get libcom_err
> trying to call UML's sem_init, even after doing
>  objcopy --redefine-sym sem_init=uml_sem_init
> 
> 
> > How does UML handle symbol conflicts between userspace code and Linux
> > kernel (like this case sem_init) ?  AFAIK, libnl has a same symbol as
> > Linux kernel (genlmsg_put) and others can possibly do as well.
> 
> I think like I said it just doesn't but since you don't have much
> userspace code linked with UML it never really mattered?
> 
> We only link a 'linux' binary, after all. How does LKL handle this
> though? It should be far more affected?
> 
> 
> Despite the objcopy *not* fixing it, this does seem to:

with slightly old version:
 - objcopy/ld version 2.29.1-23.fc28

I confirmed that objcopy (both --redefine-sym and --localize-symbol)
only changes symbols of .symtab table.  But there is another table,
.dynsym table, which is used to resolve.
So, the original file looks like this:


1) before objcopy (vmlinux)
% readelf -s obj-x86-um/vmlinux |grep -E "sem_init|Symbol table|Num:"
Symbol table '.dynsym' contains 179 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
   129: 0000000060011d38    72 FUNC    GLOBAL DEFAULT    2 sem_init
Symbol table '.symtab' contains 38474 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
 28515: 0000000060011d38    72 FUNC    GLOBAL DEFAULT    2 sem_init
 37798: 00000000601e30d5    62 FUNC    GLOBAL DEFAULT   13 sem_init_ns
 
the result object looks like

2) after objcopy (linux)
% readelf -s obj-x86-um/linux |grep -E "sem_init|Symbol table|Num:"
Symbol table '.dynsym' contains 179 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
   129: 0000000060011d38    72 FUNC    GLOBAL DEFAULT    2 sem_init
Symbol table '.symtab' contains 38474 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
 28455: 0000000060011d38    72 FUNC    LOCAL  DEFAULT    2 sem_init
 37798: 00000000601e30d5    62 FUNC    GLOBAL DEFAULT   13 sem_init_ns

Only .symtab symbol table is changed to local while .dynsym table is
not changed.  So, sem_init call from libcom_err.so still can resolve
the Linux symbol.


On the other hand, ld --version script solution does as we wish.

3) localized with ld
% readelf -s obj-x86-um/linux G -E "sem_init|Symbol table|Num:" 
Symbol table '.dynsym' contains 142 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
Symbol table '.symtab' contains 38474 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
 28512: 0000000060011d38    72 FUNC    LOCAL  DEFAULT    2 sem_init
 37669: 00000000601e2b45    62 FUNC    LOCAL  DEFAULT   13 sem_init_ns

Only .symtab table is generated for the sem_init symbol and it's localized.


Because the way to build is different from what UML currently does,
LKL (and UML binaries) do not have this issue, with a quick check.

LKL applies objcopy before generating intermediate file (linux.o), and
the symbols of the final binary (linux) are localized and have no
.dynsym entries, thus no issue in this case.

refs:
https://stackoverflow.com/questions/54332797/binding-failure-with-objcopy-redefine-syms
https://sourceware.org/legacy-ml/binutils/2019-01/msg00254.html


-- Hajime

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


  parent reply	other threads:[~2021-03-07 12:22 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23  8:06 linux uml segfault Ritesh Raj Sarraf
2021-02-23 10:50 ` Anton Ivanov
2021-02-23 12:12   ` Christopher Obbard
2021-02-23 12:24     ` Anton Ivanov
2021-02-23 17:19     ` Anton Ivanov
2021-02-23 17:26       ` Ritesh Raj Sarraf
2021-02-23 18:02         ` Anton Ivanov
2021-02-24 11:44         ` Anton Ivanov
2021-03-02  9:09           ` Ritesh Raj Sarraf
2021-03-02 11:34             ` Anton Ivanov
2021-03-02 14:23               ` Ritesh Raj Sarraf
2021-03-02 17:05                 ` Anton Ivanov
2021-03-02 17:27                   ` Ritesh Raj Sarraf
2021-03-03  9:30                     ` Anton Ivanov
2021-03-03 10:45                       ` Bug#983379: " Ritesh Raj Sarraf
2021-03-03 10:53                         ` Anton Ivanov
2021-03-03 22:40                     ` Johannes Berg
2021-03-04  5:38                       ` Hajime Tazaki
2021-03-04  7:45                         ` Anton Ivanov
2021-03-04  7:47                         ` Johannes Berg
2021-03-04  8:05                           ` Benjamin Berg
2021-03-04 18:41                             ` Anton Ivanov
2021-03-05  9:59                               ` Anton Ivanov
2021-03-05 10:07                                 ` Johannes Berg
2021-03-05 17:39                           ` Anton Ivanov
2021-03-05 18:32                             ` Johannes Berg
2021-03-05 19:03                               ` Anton Ivanov
2021-03-05 20:06                                 ` Johannes Berg
2021-03-05 20:07                             ` Johannes Berg
2021-03-05 20:22                         ` Johannes Berg
2021-03-05 22:25                           ` Hajime Tazaki
2021-03-07 12:22                           ` Hajime Tazaki [this message]
2021-03-07 12:56                             ` Johannes Berg
2021-03-04  7:28                       ` Anton Ivanov
2021-03-04  7:43                         ` Johannes Berg
2021-03-05 19:54                       ` Johannes Berg
2021-03-05 20:43 ` [PATCH] um: mark all kernel symbols as local Johannes Berg
2021-03-05 20:54   ` Anton Ivanov
2021-03-06 10:51     ` Ritesh Raj Sarraf
2021-03-08 10:29       ` Bug#983379: " Ritesh Raj Sarraf
2021-03-08 10:33         ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sg57jgqy.wl-thehajime@gmail.com \
    --to=thehajime@gmail.com \
    --cc=983379@bugs.debian.org \
    --cc=anton.ivanov@kot-begemot.co.uk \
    --cc=chris.obbard@collabora.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-um@lists.infradead.org \
    --cc=rrs@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.