Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-28162

clang compiler emits atomic library calls on x86/32bit

Details

    Description

      Clang expects 8-byte alignment for some 64-bit atomic operations
      in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
      should only require 4-byte alignment.

      As a result laterst mariadb fails to build with clang on 32bit/x86 architecture because it
      can not find the missing symbol

      undefined reference to `__atomic_fetch_or_8'

      here is a shortened testcase that can reproduce the problem with clang

      #include <stdint.h>
      # ifdef __GNUC__
      typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
      # else
      typedef uint64_t ATOMIC_U64;
      # endif
       
      int main() {return 0;}
       
      #ifdef BUGGY
      uint64_t foo(uint64_t *val, uint64_t op)
      #else
      uint64_t foo(ATOMIC_U64 *val, uint64_t op)
      #endif
      {
          return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
      }
       
      
      

      compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

      `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

      and you see the difference. Clang says

      /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
          return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                 ^
      1 warning generated.
      /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
      a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
      clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
       
      
      

      but gcc sails along.

      so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
      help the compiler a bit here.

      Attachments

        Issue Links

          Activity

            khem KHEM RAJ created issue -
            khem KHEM RAJ made changes -
            Field Original Value New Value
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            ```c
            #include <stdint.h>

            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            ```

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang


            {{#include <stdint.h>

            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }}}


            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            khem KHEM RAJ made changes -
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang


            {{#include <stdint.h>

            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }}}


            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            {{
            #include <stdint.h>

            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            }}
            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            khem KHEM RAJ made changes -
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            {{
            #include <stdint.h>

            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            }}
            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            #include <stdint.h>
            {{monospaced text}}
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            khem KHEM RAJ made changes -
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            #include <stdint.h>
            {{monospaced text}}
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            #include <stdint.h>
            {{monospaced text
            monot
            }}
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            khem KHEM RAJ made changes -
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            #include <stdint.h>
            {{monospaced text
            monot
            }}
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            #include <stdint.h>
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            khem KHEM RAJ made changes -
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang

            #include <stdint.h>
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }

            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says

            ```
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

            ```

            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang


            {code:c}
            #include <stdint.h>
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }


            {code}
            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says



            {noformat}
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)


            {noformat}


            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            khem KHEM RAJ made changes -
            Attachment clang-64bit-atomics.patch [ 62711 ]
            khem KHEM RAJ made changes -
            Attachment clang-64bit-atomics.patch [ 62711 ]
            khem KHEM RAJ made changes -
            Attachment clang-64bit-atomics.patch [ 62712 ]
            marko Marko Mäkelä made changes -
            Component/s Performance Schema [ 15627 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Affects Version/s 10.2 [ 14601 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            Affects Version/s 10.5 [ 23123 ]
            Affects Version/s 10.6 [ 24028 ]
            Affects Version/s 10.7 [ 24805 ]
            Affects Version/s 10.8 [ 26121 ]
            Affects Version/s 10.9 [ 26905 ]
            Labels alignment beginner-friendly c++
            serg Sergei Golubchik made changes -
            Assignee Daniel Black [ danblack ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            serg Sergei Golubchik made changes -
            Assignee Daniel Black [ danblack ] Nikita Malyavin [ nikitamalyavin ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.7 [ 24805 ]
            nikitamalyavin Nikita Malyavin made changes -
            nikitamalyavin Nikita Malyavin made changes -
            marko Marko Mäkelä made changes -
            Fix Version/s 10.5.26 [ 29832 ]
            Fix Version/s 10.6.19 [ 29833 ]
            Fix Version/s 10.11.9 [ 29834 ]
            Fix Version/s 11.1.6 [ 29835 ]
            Fix Version/s 11.2.5 [ 29836 ]
            Fix Version/s 11.4.3 [ 29837 ]
            Fix Version/s 11.5.2 [ 29838 ]
            Fix Version/s 11.6.1 [ 29847 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            nikitamalyavin Nikita Malyavin made changes -
            Description Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang


            {code:c}
            #include <stdint.h>
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }


            {code}
            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says



            {noformat}
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)


            {noformat}


            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.
            Clang expects 8-byte alignment for some 64-bit atomic operations
            in some 32-bit targets. Native instruction lock cmpxchg8b (for x86)
            should only require 4-byte alignment.

            As a result laterst mariadb fails to build with clang on 32bit/x86 architecture because it
            can not find the missing symbol

            undefined reference to `__atomic_fetch_or_8'

            here is a shortened testcase that can reproduce the problem with clang


            {code:c}
            #include <stdint.h>
            # ifdef __GNUC__
            typedef __attribute__((__aligned__(8))) uint64_t ATOMIC_U64;
            # else
            typedef uint64_t ATOMIC_U64;
            # endif

            int main() {return 0;}

            #ifdef BUGGY
            uint64_t foo(uint64_t *val, uint64_t op)
            #else
            uint64_t foo(ATOMIC_U64 *val, uint64_t op)
            #endif
            {
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
            }


            {code}
            compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with

            `gcc -DBUGGY -m32` or `clang -DBUGGY -m32`

            and you see the difference. Clang says



            {noformat}
            /tmp/a.c:17:12: warning: misaligned atomic operation may incur significant performance penalty; the expected alignment (8 bytes) exceeds the actual alignment (4 bytes) [-Watomic-alignment]
                return __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
                       ^
            1 warning generated.
            /usr/bin/ld: /tmp/a-4a5d79.o: in function `foo':
            a.c:(.text+0x6b): undefined reference to `__atomic_fetch_or_8'
            clang-13: error: linker command failed with exit code 1 (use -v to see invocation)


            {noformat}


            but gcc sails along.

            so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to
            help the compiler a bit here.

            People

              nikitamalyavin Nikita Malyavin
              khem KHEM RAJ
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.