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

            Bug ID: 81697
           Summary: Incorrect ASan global variables alignment on arm
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: v.barinov at samsung dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

Created attachment 41914
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41914&action=edit
proposed fix

I have the following code:

#include <string>
#include <map>

const char kRecoveryInstallString[] = "NEW";
const char kRecoveryUpdateString[] = "UPDATE";
const char kRecoveryUninstallationString[] = "UNINSTALL";

const std::map<std::string, int> kStringToRequestMap = {
  {kRecoveryInstallString, 0},
  {kRecoveryUpdateString, 0},
  {kRecoveryUninstallationString, 0},
};

While compilation for armv7l with -O1 -fmerge-all-constants -fsanitize=address
ASan global variables with strings are placed into section '.rodata.str1.4'
which is not aligned by 64 bytes and mixed with ASan own strings. This leads to
strip during link time and false positive ASan reports due to wrong resulting
red zones size.

Original state:

  0x000041a0 554e494e 5354414c 4c000000 00000000 UNINSTALL.......
  0x000041b0 00000000 00000000 00000000 00000000 ................
  0x000041c0 55504441 54450000 00000000 00000000 UPDATE..........
  0x000041d0 00000000 00000000 00000000 00000000 ................
  0x000041e0 4e455700 00000000 00000000 00000000 NEW.............
  0x000041f0 00000000 00000000 00000000 00000000 ................
  0x00004200 6b537472 696e6754 6f526571 75657374 kStringToRequest
  0x00004210 4d617000 6b526563 6f766572 794d6f75 Map.kRecoveryMou
  0x00004220 6e745570 64617465 53747269 6e670000 ntUpdateString..
  0x00004230 6b526563 6f766572 794d6f75 6e74496e kRecoveryMountIn

After disabling section-anchors everything works as intended:

  0x000047c0 55504441 54450000 00000000 00000000 UPDATE..........
  0x000047d0 00000000 00000000 00000000 00000000 ................
  0x000047e0 00000000 00000000 00000000 00000000 ................
  0x000047f0 00000000 00000000 00000000 00000000 ................
  0x00004800 4e455700 00000000 00000000 00000000 NEW.............
  0x00004810 00000000 00000000 00000000 00000000 ................
  0x00004820 00000000 00000000 00000000 00000000 ................
  0x00004830 00000000 00000000 00000000 00000000 ................
  0x00004840 35203332 20312039 203c756e 6b6e6f77 5 32 1 9 <unknow
  0x00004850 6e3e2039 36203120 39203c75 6e6b6e6f n> 96 1 9 <unkno
  0x00004860 776e3e20 31363020 34203320 5f5f6a20 wn> 160 4 3 __j
  0x00004870 32323420 34203920 3c756e6b 6e6f776e 224 4 9 <unknown
  0x00004880 3e203238 38203420 39203c75 6e6b6e6f > 288 4 9 <unkno

Reply via email to