This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH 1/2] x86: Support Intel IBT with IBT property and IBT-enable PLT
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Simon Marchi <simon dot marchi at ericsson dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Thu, 22 Jun 2017 14:31:18 -0700
- Subject: Re: [PATCH 1/2] x86: Support Intel IBT with IBT property and IBT-enable PLT
- Authentication-results: sourceware.org; auth=none
- References: <07e82ea7-8b15-2059-ce8e-197168eb4fcd@ericsson.com>
On Thu, Jun 22, 2017 at 1:52 PM, Simon Marchi <simon.marchi@ericsson.com> wrote:
> Hi,
>
> clang shows this warning for the code added by this patch. I am not familiar with this
> code, but it seems to me like it's not a false positive.
>
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7408:8: error: variable 'htab' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
> if (!bfd_set_section_alignment (ebfd, sec, 2))
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7574:9: note: uninitialized use occurs here
> sec = htab->elf.sgotplt;
> ^~~~
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7408:4: note: remove the 'if' if its condition is always false
> if (!bfd_set_section_alignment (ebfd, sec, 2))
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7351:42: note: initialize the variable 'htab' to silence this warning
> struct elf_x86_64_link_hash_table *htab;
> ^
> = NULL
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7408:8: error: variable 'dynobj' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
> if (!bfd_set_section_alignment (ebfd, sec, 2))
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7575:35: note: uninitialized use occurs here
> if (!bfd_set_section_alignment (dynobj, sec, 3))
> ^~~~~~
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7408:4: note: remove the 'if' if its condition is always false
> if (!bfd_set_section_alignment (ebfd, sec, 2))
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/emaisin/src/binutils-gdb/bfd/elf64-x86-64.c:7348:14: note: initialize the variable 'dynobj' to silence this warning
> bfd *dynobj;
> ^
> = NULL
>
I checked in this patch to silence clang.
Thanks.
--
H.J.
From 5d8763a38211dd79459485ba0be4f76849ef8200 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 22 Jun 2017 14:26:09 -0700
Subject: [PATCH] x86-64: Move the error_alignment label forward
Move the error_alignment label forward to avoid clang warning on
if (!bfd_set_section_alignment (ebfd, sec, 2))
goto error_alignment;
htab = elf_x86_64_hash_table (info);
error_alignment:
info->callbacks->einfo (_("%F%A: failed to align section\n"), sec);
"%F" causes a fatal linker error and
immediate exit.
sec = htab->elf.sgotplt;
Also fix alignment on program property note section.
* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Move
the error_alignment label forward. Properly align program
property note section.
---
bfd/ChangeLog | 6 ++++++
bfd/elf64-x86-64.c | 15 ++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 8fa42f7..4d2acc5 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-22 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Move
+ the error_alignment label forward. Properly align program
+ property note section.
+
2017-06-22 Eric Christopher <echristo@gmail.com>
* elf32-arm.c (elf32_arm_final_link_relocate): Use labs rather than
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 957dcd9..8cef9f5 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -7407,8 +7407,13 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
if (sec == NULL)
info->callbacks->einfo (_("%F: failed to create GNU property section\n"));
- if (!bfd_set_section_alignment (ebfd, sec, 2))
- goto error_alignment;
+ if (!bfd_set_section_alignment (ebfd, sec,
+ ABI_64_P (ebfd) ? 3 : 2))
+ {
+error_alignment:
+ info->callbacks->einfo (_("%F%A: failed to align section\n"),
+ sec);
+ }
elf_section_type (sec) = SHT_NOTE;
}
@@ -7567,11 +7572,7 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
properly aligned even if create_dynamic_sections isn't called. */
sec = htab->elf.sgot;
if (!bfd_set_section_alignment (dynobj, sec, 3))
- {
-error_alignment:
- info->callbacks->einfo (_("%F%A: failed to align section\n"),
- sec);
- }
+ goto error_alignment;
sec = htab->elf.sgotplt;
if (!bfd_set_section_alignment (dynobj, sec, 3))
--
2.9.4