https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92902

            Bug ID: 92902
           Summary: gcc 9.2 puts "jump tables" in the .text section
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at tribudubois dot net
  Target Milestone: ---

gcc 9.2 (and maybe other versions) is putting jump table directly in the text
section.

On most processors I guess this is not an issue as the text section is usually
readable.

But on some processors like (like the SPARC processor) this is an issue when
user space text section is protected (from the OS) with an "eXecute Only" MMU
protection.

In such case when the code is trying to read the jump table from the text
section, a data abort exception is generated and the all application is
crashed.

To work around the problem I have to either:
* change the protection (from the OS) on the text segment to "Read and eXecute"
* compile with the -fno-jump-table command line option.

These 2 work arroud allow the application code (that use to work OK on gcc 8
and gcc 7) to run again when comiled with gcc 9

I believe the jump_table should go in the ro_data section. Putting them in the
text section seems wrong. A jump table is data after all.

Another solution is to avoid generating "jump tables" on
processors/architecture that could put "eXecute Only" MMU protection on text
segments.

On SPARC/LEON there is also the -muser_mode command line option that could be
used to avoid generating jump tables if it is not possible to move them in the
ro_data section.

Reply via email to