This is an archive of the discontinued LLVM Phabricator instance.

Fix Thumb text sections' flags under COFF/Windows (2/2)
ClosedPublic

Authored by aguinet on Jun 23 2016, 3:14 PM.

Details

Reviewers
rengolin
compnerd
Summary

This is a follow up of D21662.

The main issue here is that the "thumb" flag wasn't set for some of these
sections, making MSVC's link.exe fails to correctly relocate code
against the symbols inside these sections. link.exe could fail for
instance with the "fixup is not aligned for target 'XX'" error. If
linking doesn't fail, the relocation process goes wrong in the end and
invalid code is generated by the linker.

To reproduce the error, one can compile this file as a static library:

#include <stdio.h>

void test(const char* s)
{
const void* ptr = &snprintf;
printf("%s: %p\n", s, ptr);
}

and then create a dynamic library that links against this static library
(which calls the 'test' function). A visual studio project can be
provided for people interested.

Diff Detail

Event Timeline

aguinet updated this revision to Diff 61733.Jun 23 2016, 3:14 PM
aguinet retitled this revision from to Fix Thumb text sections' flags under COFF/Windows (2/2).
aguinet updated this object.
aguinet added reviewers: rengolin, compnerd.
compnerd accepted this revision.Jun 23 2016, 5:35 PM
compnerd edited edge metadata.

Nice find on this. Modulo the comment/style things, this LGTM.

lib/CodeGen/TargetLoweringObjectFileImpl.cpp
825

The same thing applies to lld ;-). This is not link.exe specific.

The flag isn't "basically" telling the linker, it is exactly telling the linker that. This is a carry over from the older ARM support: thumb(-1) was 16-bit instructions, and the IMAGE_SCN_MEM_16BIT indicates that the text is 16-bit instructions, aka thumb mode.

I don't think that the comment adds anything of value.

828

Kill the unnecessary braces.

I think you can write this more compactly by doing:

| (TM.getTargetTriple().getArch() == Triple::thumb ? COFF::IMAGE_SCN_MEM_16BIT : 0)
This revision is now accepted and ready to land.Jun 23 2016, 5:35 PM
rengolin accepted this revision.Jun 25 2016, 3:43 AM
rengolin edited edge metadata.

With Saleem's comments. LGTM.

rengolin closed this revision.Jun 27 2016, 7:49 AM

r273880