1. 20 May, 2022 2 commits
    • Mikulas Patocka's avatar
      objtool: Fix objtool regression on x32 systems · 22682a07
      Mikulas Patocka authored
      Commit c087c6e7 ("objtool: Fix type of reloc::addend") failed to
      appreciate cross building from ILP32 hosts, where 'int' == 'long' and
      the issue persists.
      
      As such, use s64/int64_t/Elf64_Sxword for this field and suffer the
      pain that is ISO C99 printf formats for it.
      
      Fixes: c087c6e7 ("objtool: Fix type of reloc::addend")
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      [peterz: reword changelog, s/long long/s64/]
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Cc: <stable@vger.kernel.org>
      Link: https://lkml.kernel.org/r/alpine.LRH.2.02.2205161041260.11556@file01.intranet.prod.int.rdu2.redhat.com
      22682a07
    • Peter Zijlstra's avatar
      objtool: Fix symbol creation · ead165fa
      Peter Zijlstra authored
      Nathan reported objtool failing with the following messages:
      
        warning: objtool: no non-local symbols !?
        warning: objtool: gelf_update_symshndx: invalid section index
      
      The problem is due to commit 4abff6d4 ("objtool: Fix code relocs
      vs weak symbols") failing to consider the case where an object would
      have no non-local symbols.
      
      The problem that commit tries to address is adding a STB_LOCAL symbol
      to the symbol table in light of the ELF spec's requirement that:
      
        In each symbol table, all symbols with STB_LOCAL binding preced the
        weak and global symbols.  As ``Sections'' above describes, a symbol
        table section's sh_info section header member holds the symbol table
        index for the first non-local symbol.
      
      The approach taken is to find this first non-local symbol, move that
      to the end and then re-use the freed spot to insert a new local symbol
      and increment sh_info.
      
      Except it never considered the case of object files without global
      symbols and got a whole bunch of details wrong -- so many in fact that
      it is a wonder it ever worked :/
      
      Specifically:
      
       - It failed to re-hash the symbol on the new index, so a subsequent
         find_symbol_by_index() would not find it at the new location and a
         query for the old location would now return a non-deterministic
         choice between the old and new symbol.
      
       - It failed to appreciate that the GElf wrappers are not a valid disk
         format (it works because GElf is basically Elf64 and we only
         support x86_64 atm.)
      
       - It failed to fully appreciate how horrible the libelf API really is
         and got the gelf_update_symshndx() call pretty much completely
         wrong; with the direct consequence that if inserting a second
         STB_LOCAL symbol would require moving the same STB_GLOBAL symbol
         again it would completely come unstuck.
      
      Write a new elf_update_symbol() function that wraps all the magic
      required to update or create a new symbol at a given index.
      
      Specifically, gelf_update_sym*() require an @ndx argument that is
      relative to the @data argument; this means you have to manually
      iterate the section data descriptor list and update @ndx.
      
      Fixes: 4abff6d4 ("objtool: Fix code relocs vs weak symbols")
      Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Acked-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Cc: <stable@vger.kernel.org>
      Link: https://lkml.kernel.org/r/YoPCTEYjoPqE4ZxB@hirez.programming.kicks-ass.net
      ead165fa
  2. 12 May, 2022 4 commits
  3. 22 Apr, 2022 20 commits
  4. 19 Apr, 2022 14 commits