[llvm-bugs] [Bug 38553] New: When compiling for arch armv6kz, __ARM_FEATURE_LDREX predefined incorrectly

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 13 22:14:47 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38553

            Bug ID: 38553
           Summary: When compiling for arch armv6kz, __ARM_FEATURE_LDREX
                    predefined incorrectly
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sethml at ofb.net
                CC: llvm-bugs at lists.llvm.org

When compiling with arch armv6kz, __ARM_FEATURE_LDREX is predefined to 0x4,
while when compiling for armv6k it's predefined to 0xf:

% clang++ -E -dM --target=arm-linux-gnueabihf -march=armv6kz - </dev/null |
grep LDREX
#define __ARM_FEATURE_LDREX 0x4
% clang++ -E -dM --target=arm-linux-gnueabihf -march=armv6k - </dev/null | grep
LDREX
#define __ARM_FEATURE_LDREX 0xf

According to ARM's document "ARMĀ® C Language Extensions Release 2.0":

 
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf

  The following values of __ARM_FEATURE_LDREX may occur:
  Macro value | Access widths                    | Example architecture
  (undefined) | none                             | ARM v5, ARM v6-M
  0x04        | word                             | ARM v6
  0x07        | word, halfword, byte             | ARM v7-M
  0x0F        | doubleword, word, halfword, byte | ARM v6K, ARM v7-A/R

The "armv6kz" architecture is a synonym for "armv6z" and "armv6zk". It's the
architecture implemented by the ARM1176JZF-S CPU which is used in all older
Raspberry Pis, so it's a surprisingly common architecture. It's a bit hard to
find an authoritative reference in ARM's documentation, but armv6kz is a
superset of armv6k. The "ARMĀ® Architecture Reference Manual ARMv7-A and ARMv7-R
edition" on page 1156 says:
 
https://static.docs.arm.com/ddi0406/c/DDI0406C_C_arm_architecture_reference_manual.pdf

  Note:
  The Security Extensions are also permitted as an extension to the ARMv6K 
  architecture. The resulting combination is sometimes called the ARMv6Z or
ARMv6KZ 
  architecture.

As such, on this architecture __ARM_FEATURE_LDREX should be defined to 0xf.

I'm not in a position to test and submit a patch, but I think the fix is
simple. In lib/Basic/Targets/ARM.cpp ARMTargetInfo::handleTargetFeatures(),
change:
    else if (ArchKind == llvm::ARM::ArchKind::ARMV6K)
      LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
to:
    else if (ArchKind == llvm::ARM::ArchKind::ARMV6K ||
             ArchKind == llvm::ARM::ArchKind::ARMV6KZ)
      LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180814/13ce20d1/attachment.html>


More information about the llvm-bugs mailing list