[RFC] RISC-V: Go PLT for CALL/JUMP/RVC_JUMP if `h->plt.offset' isn't -1

2025-02-08 Thread Nelson Chu
I got an request about the undefined behaviors, considering the following case,

$ cat test.c
void main ()
{
  foo();
}
$ cat lib.h
void foo(void);
$ riscv64-unknown-linux-gnu-gcc test.c
riscv64-unknown-linux-gnu/bin/ld: /tmp/ccRO8fJl.o: in function `main':
test.c:(.text+0x8): undefined reference to `foo'
collect2: error: ld returned 1 exit status
$ riscv64-unknown-linux-gnu-gcc test.c 
-Wl,--unresolved-symbols=ignore-in-object-files
$ qemu-riscv64 a.out
Segmentation fault (core dumped)

Testing with x86 and aarch64, they won't get the segfault since they go plt
for the undefined foo symbol.  So, after applying this patch, I can get the
following too,

$ qemu-riscv64 a.out
a.out: symbol lookup error: a.out: undefined symbol: foo

The change of this patch should only affect the call behavior, which refer
to an undefined (weak) symbol, when building an dynamic executable.  I think
the pic/pie behavior won't be affected as usual.  I am not sure if the change
will cause trouble or not for other projects, so please feels free to cc people
that you think they will be affected, thanks.
---
 bfd/elfnn-riscv.c | 84 +--
 1 file changed, 44 insertions(+), 40 deletions(-)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 57ced95fdb3..bca3a585f56 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2263,6 +2263,7 @@ riscv_elf_relocate_section (bfd *output_bfd,
   reloc_howto_type *howto = riscv_elf_rtype_to_howto (input_bfd, r_type);
   const char *msg = NULL;
   bool resolved_to_zero;
+  bool via_plt = false;
 
   if (howto == NULL)
continue;
@@ -2565,6 +2566,12 @@ riscv_elf_relocate_section (bfd *output_bfd,
   resolved_to_zero = (h != NULL
  && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
 
+  /* Refer to the PLT entry.  This check has to match the check in
+_bfd_riscv_relax_section.  */
+  via_plt = (htab->elf.splt != NULL
+&& h != NULL
+&& h->plt.offset != MINUS_ONE);
+
   switch (r_type)
{
case R_RISCV_NONE:
@@ -2776,8 +2783,7 @@ riscv_elf_relocate_section (bfd *output_bfd,
case R_RISCV_CALL_PLT:
  /* Handle a call to an undefined weak function.  This won't be
 relaxed, so we have to handle it here.  */
- if (h != NULL && h->root.type == bfd_link_hash_undefweak
- && (!bfd_link_pic (info) || h->plt.offset == MINUS_ONE))
+ if (h->root.type == bfd_link_hash_undefweak && !via_plt)
{
  /* We can use x0 as the base register.  */
  bfd_vma insn = bfd_getl32 (contents + rel->r_offset + 4);
@@ -2791,42 +2797,40 @@ riscv_elf_relocate_section (bfd *output_bfd,
 
case R_RISCV_JAL:
case R_RISCV_RVC_JUMP:
- if (bfd_link_pic (info) && h != NULL)
+ if (via_plt)
{
- if (h->plt.offset != MINUS_ONE)
-   {
- /* Refer to the PLT entry.  This check has to match the
-check in _bfd_riscv_relax_section.  */
- relocation = sec_addr (htab->elf.splt) + h->plt.offset;
- unresolved_reloc = false;
-   }
- else if (!SYMBOL_REFERENCES_LOCAL (info, h)
-  && (input_section->flags & SEC_ALLOC) != 0
-  && (input_section->flags & SEC_READONLY) != 0
-  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
-   {
- /* PR 28509, when generating the shared object, these
-referenced symbols may bind externally, which means
-they will be exported to the dynamic symbol table,
-and are preemptible by default.  These symbols cannot
-be referenced by the non-pic relocations, like
-R_RISCV_JAL and R_RISCV_RVC_JUMP relocations.
-
-However, consider that linker may relax the R_RISCV_CALL
-relocations to R_RISCV_JAL or R_RISCV_RVC_JUMP, if
-these relocations are relocated to the plt entries,
-then we won't report error for them.
-
-Perhaps we also need the similar checks for the
-R_RISCV_BRANCH and R_RISCV_RVC_BRANCH relocations.  */
- msg = bfd_asprintf (_("%%X%%P: relocation %s against `%s'"
-   " which may bind externally"
-   " can not be used"
-   " when making a shared object;"
-   " recompile with -fPIC\n"),
- howto->name, h->root.root.string);
- r = bfd_reloc_notsupported;
-   }
+ relocation = sec_addr (htab->elf.splt) + h->plt.offset;
+ unresolved_reloc = false;
+   }
+ else if (bf

gcc-14-20250208 is now available

2025-02-08 Thread GCC Administrator via Gcc
Snapshot gcc-14-20250208 is now available on
  https://gcc.gnu.org/pub/gcc/snapshots/14-20250208/
and on various mirrors, see https://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 14 git branch
with the following options: git://gcc.gnu.org/git/gcc.git branch 
releases/gcc-14 revision 4098d67d92908d6a870bca14975d0ab88de72756

You'll find:

 gcc-14-20250208.tar.xz   Complete GCC

  SHA256=79e7f1b4ead9194b5782eb5bd3bf5080f737792e9e352529f3cbe9265bab6e93
  SHA1=fe6647ef8cf928242d0adf5bd5a78025992ef2b5

Diffs from 14-20250201 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-14
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.


Classes Implicitly Declared

2025-02-08 Thread Frederick Virchanza Gotham via Gcc
As the GNU compiler make its way through a translation unit, more and
more classes get declared. So for each translation unit, the compiler
maintains a list of what types it has seen so far.

Could someone please point me to where in the GNU g++ source code I
will find this container object? What's the name of the container, and
in what source file is it defined?

I want to add 'std::vector' to the container implicitly so that we can
write a translation unit without needing to do "#include ". My
end game idea is to add forward declarations for all standard library
classes.


, Welcome to the formation of the IWACCE 2025 session!

2025-02-08 Thread IWACCE 2025 via Gcc
Welcome to form an IWACCE 2025 session!

The 4th International Workshop on Automation, Control and Communication 
Engineering (lWACCE2025) will be held in Changchun, China from August 8 to 10, 
2025!

(Detail: 
http://email.ms.iwacce.org/c/eJxMy7FugzAQANCvsUd0vjtjGDxAFNQsbZeQbpZru0CT0ihAnfx9pU6dn160PtYVkExWGaoBSqVZjpaQTQQOSAa9QYWJyESqfOQS6hDlmN05PWy-H_sTbQv057tTc2qdmnuHnx_bcZveLi9Pa7i2bR-bwys_wIGcLAJqQKigVlpzobRBJl3p94pL9CgYvpZiyj6EVHzfBnmx47peF0GNwE5gl3P-xwI7ebNDCIJhCKEY5u1vrfZwana7Pbv9s_yx-BsAAP__iQJEnw)

Organizer

College of Communication Engineering, Jilin University

Changchun Guanghua University

Co-organizer

College of Information and Electrical Engineering, China Agricultural University

College of Electric Power, Inner Mongolia University of Technology

Jilin Association of Automation

Zhejiang Association of Automation

Session Proposals

Interested scholars are welcome to submit academic session proposals around the 
IWACCE 2025 conference theme, self-nominate or recommend experts and scholars 
to become session chairs/members, and organize the promotion and successful 
convening of the session.

Academic session proposals include: session name, background description, 
session theme, organizer/ session chair, etc.
Please send your proposal to secret...@iwacce.org via email and the organizing 
committee will give you feedback in the first instance.
Duties of the session chair

(1) Formulate the session topics & chapter call for papers areas (the template 
of the session will be provided by the conference team, we will update it to 
the official website after the session is finalized, and make posters of the 
session for publicity;

(2) Generally the session chair needs to attend and host the meeting (online or 
offline are available);

(3) The organizing committee will be responsible for handling of articles, and 
the session chair will be required to help adjudicate any controversial 
articles.

IWACCE 2025 Organizing Committee

Email: secret...@iwacce.org

Tel/Wechat: 15549059767

If you are not interested, please click here to unsubscribe. Thanks for your 
time.