LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 32770 - CFI tests using ThinLTO on Windows all fail with unsupported X86 relocation
Summary: CFI tests using ThinLTO on Windows all fail with unsupported X86 relocation
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Linker (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-24 10:37 PDT by Reid Kleckner
Modified: 2017-09-15 11:55 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Kleckner 2017-04-24 10:37:20 PDT
This was found after Evgeniy's refactoring of the CFI tests in r301016.

The failing tests:
Failing Tests (4):
    cfi-devirt-lld-thinlto :: simple-pass.cpp
    cfi-devirt-thinlto :: simple-pass.cpp
    cfi-standalone-lld-thinlto :: simple-pass.cpp
    cfi-standalone-thinlto :: simple-pass.cpp

Example build:
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/10028/

LLD crashes when attempting to emit a COFF object after ThinLTO optimization:

$ "C:/b/slave/sanitizer-windows/build/./bin/clang.exe" "-fuse-ld=lld" "-Wl,-nopdb" "-flto=thin" "-fsanitize=cfi" "-fvisibility=hidden" "-o" "C:\b\slave\sanitizer-windows\build\projects\compiler-rt\test\cfi\Standalone-thinlto\Output\simple-pass.cpp.tmp" "C:\b\slave\sanitizer-windows\llvm\projects\compiler-rt\test\cfi\simple-pass.cpp"
# command stderr:
unsupported relocation type

UNREACHABLE executed at C:\b\slave\sanitizer-windows\llvm\lib\Target\X86\MCTargetDesc\X86WinCOFFObjectWriter.cpp:92!
Comment 1 Peter Collingbourne 2017-04-24 10:56:42 PDT
ThinLTO + CFI may use 8-bit relocations (R_X86_64_8 in ELF) to absolute symbols whose values are in range 0-255. Absolute symbols exist in COFF, but there is no direct analog for the relocation. That is what I suspect the cause of the assertion failure to be.

The solution I had in mind was to use IMAGE_REL_AMD64_SECREL7, and have LLD extend its meaning to allow for 8-bit values and absolute symbols (this may not work with /msvclto though).
Comment 2 Evgenii Stepanov 2017-04-24 13:04:30 PDT
Disabled the tests for now in r301235
Comment 3 Hans Wennborg 2017-04-24 14:31:56 PDT
I got test failures at r301243 still: https://codereview.chromium.org/2843513003

And it looks like the bot from #0 is still red.
Comment 4 Evgenii Stepanov 2017-04-24 14:39:03 PDT
Ouch. r301257. I love CMake.
Comment 5 Peter Collingbourne 2017-06-20 18:08:34 PDT
It looks like the MSVC linker rejects SECRELs pointing to absolute symbols, so this probably won't work with /msvclto.

C:\src\secrel7>type 1.s
        .text
        .data
        .globl  p                       # @p
        .p2align        3
.zero 128
p:
.byte 0x12
.byte 0x34
.byte 0x56
.byte 0x78
        .long   i@secrel32
 
 
 
C:\src\secrel7>type 2.s
.globl  i
i = 42
 
 
 
C:\src\secrel7>\src\llvm-project\ra\bin\llvm-mc -filetype=obj -o 1.obj 1.s
 
C:\src\secrel7>\src\llvm-project\ra\bin\llvm-mc -filetype=obj -o 2.obj 2.s
 
C:\src\secrel7>link 1.obj 2.obj /entry:ExitProcess kernel32.lib /subsystem:console
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.
 
1.obj : error LNK2016: absolute symbol 'i' used as target of SECREL relocation in section 2
LINK : fatal error LNK1165: link failed because of fixup errors
Comment 6 Peter Collingbourne 2017-09-14 19:05:49 PDT
I ended up fixing this another way at least for now, by avoiding the use of absolute symbols on everything except x86 + ELF. https://reviews.llvm.org/D37883 should re-enable the tests.
Comment 7 Peter Collingbourne 2017-09-15 11:55:57 PDT
The change to re-enable the tests landed in r313379.