[PATCH] Use an 'l' prefix when an 'L' prefix would produce an invalid MachO

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Sun Feb 9 08:38:08 PST 2014


rafael added you to the CC list for the revision "Use an 'l' prefix when an 'L' prefix would produce an invalid MachO".

Hi grosbach,

Fix PR18743.

Given the perfectly valid IR

@foo = private constant i32 42

llvm currently produces an invalid MachO:

	.section	__TEXT,__const
L_foo:                                  ## @foo
	.asciz	"abc"

It is invalid because __TEXT,__const is atomized via symbols, and L_foo will not be visible to the linker causing an invalid atomization.

This is a pretty big foot gun that has hit asan in the past and is likely to hit FE authors. Given that there is no general purpose section that is not atomized by symbols, the only two options I can see are

* Reject this IR at codegen if targeting MachO
* Produce a symbol using an 'l' prefix instead.

The second option is quiet a bit friendlier to users, so I tried to implement it first.

What this patch does is
* Add a CannotUsePrivateLabel to the Mangler getNameWithPrefix. This is a small failure in the goal of having an IR GlobalValue map directly to a name, but it is OK since only applies to private labels, which don't need to be handled by llvm-ar or llvm-nm (which are going to be the two users of the Mangler that don't link with target).
* Add a isSectionAtomizableBySymbols to TargetLoweringObjectFileImpl. This contains the logic for deciding if putting a L label in a section would break it.
* Add a getNameWithPrefix to TargetMachine. It is a convenient spot for using isSectionAtomizableBySymbols.
* Pass a TM via a few callers so that they can use TM::getNameWithPrefix.



http://llvm-reviews.chandlerc.com/D2727

Files:
  include/llvm/CodeGen/AsmPrinter.h
  include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  include/llvm/IR/Mangler.h
  include/llvm/Target/TargetLoweringObjectFile.h
  include/llvm/Target/TargetMachine.h
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
  lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
  lib/CodeGen/AsmPrinter/Win64Exception.cpp
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  lib/ExecutionEngine/MCJIT/MCJIT.cpp
  lib/IR/Mangler.cpp
  lib/LTO/LTOCodeGenerator.cpp
  lib/LTO/LTOModule.cpp
  lib/Target/ARM/ARMTargetObjectFile.cpp
  lib/Target/ARM/ARMTargetObjectFile.h
  lib/Target/PowerPC/PPCMCInstLower.cpp
  lib/Target/Sparc/SparcTargetObjectFile.cpp
  lib/Target/Sparc/SparcTargetObjectFile.h
  lib/Target/TargetLoweringObjectFile.cpp
  lib/Target/TargetMachine.cpp
  lib/Target/X86/X86MCInstLower.cpp
  lib/Target/X86/X86TargetObjectFile.cpp
  lib/Target/X86/X86TargetObjectFile.h
  lib/Target/XCore/XCoreTargetObjectFile.cpp
  test/CodeGen/PowerPC/private.ll
  test/CodeGen/X86/2009-11-16-UnfoldMemOpBug.ll
  test/CodeGen/X86/pr10420.ll
  test/CodeGen/X86/private-2.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2727.1.patch
Type: text/x-patch
Size: 44345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140209/b194e1ed/attachment.bin>


More information about the llvm-commits mailing list