Commit cb165ca3 by Jan Voung

Handle ffunction-sections w/ filetype=obj.

Just create a new section of the appropriate name, instead of trying to reuse the .text section. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4080 R=stichnot@chromium.org Review URL: https://codereview.chromium.org/948943004
parent 9738a9ea
...@@ -218,9 +218,11 @@ void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, ...@@ -218,9 +218,11 @@ void ELFObjectWriter::writeFunctionCode(const IceString &FuncName,
assert(!SectionNumbersAssigned); assert(!SectionNumbersAssigned);
ELFTextSection *Section = nullptr; ELFTextSection *Section = nullptr;
ELFRelocationSection *RelSection = nullptr; ELFRelocationSection *RelSection = nullptr;
if (TextSections.empty()) { const bool FunctionSections = Ctx.getFlags().getFunctionSections();
// TODO(jvoung): handle ffunction-sections. if (TextSections.empty() || FunctionSections) {
IceString SectionName = ".text"; IceString SectionName = ".text";
if (FunctionSections)
SectionName += "." + FuncName;
bool IsELF64 = isELF64(Ctx.getTargetArch()); bool IsELF64 = isELF64(Ctx.getTargetArch());
const Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR; const Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR;
// TODO(jvoung): Should be bundle size. Grab it from that target? // TODO(jvoung): Should be bundle size. Grab it from that target?
...@@ -254,9 +256,8 @@ void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, ...@@ -254,9 +256,8 @@ void ELFObjectWriter::writeFunctionCode(const IceString &FuncName,
OffsetInSection, SymbolSize); OffsetInSection, SymbolSize);
StrTab->add(FuncName); StrTab->add(FuncName);
// Create a relocation section for the text section if needed, and copy the // Copy the fixup information from per-function Assembler memory to the
// fixup information from per-function Assembler memory to the object // object writer's memory, for writing later.
// writer's memory, for writing later.
if (!Asm->fixups().empty()) { if (!Asm->fixups().empty()) {
RelSection->addRelocations(OffsetInSection, Asm->fixups()); RelSection->addRelocations(OffsetInSection, Asm->fixups());
} }
......
; Tests filetype=obj with -ffunction-sections.
; RUN: %p2i -i %s --args -O2 --verbose none -filetype=obj -o %t \
; RUN: -ffunction-sections && \
; RUN: llvm-readobj -file-headers -sections -section-data \
; RUN: -relocations -symbols %t | FileCheck %s
; RUN: %p2i -i %s --args -O2 --verbose none -ffunction-sections \
; RUN: | llvm-mc -triple=i686-none-nacl -filetype=obj -o - \
; RUN: | llvm-readobj -file-headers -sections -section-data \
; RUN: -relocations -symbols - | FileCheck %s
declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
define internal i32 @foo(i32 %x, i32 %len) {
%y = add i32 %x, %x
%dst = inttoptr i32 %y to i8*
%src = inttoptr i32 %x to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src,
i32 %len, i32 1, i1 false)
ret i32 %y
}
define internal i32 @bar(i32 %x) {
ret i32 %x
}
define void @_start(i32 %x) {
%y = call i32 @bar(i32 4)
%ignored = call i32 @foo(i32 %x, i32 %y)
ret void
}
; CHECK: Section {
; CHECK: Name: .text.foo
; CHECK: Type: SHT_PROGBITS
; CHECK: Flags [ (0x6)
; CHECK: SHF_ALLOC
; CHECK: SHF_EXECINSTR
; CHECK: ]
; CHECK: }
; CHECK: Section {
; CHECK: Name: .rel.text.foo
; CHECK: Type: SHT_REL
; CHECK: Flags [ (0x0)
; CHECK: ]
; CHECK: }
; CHECK: Section {
; CHECK: Name: .text.bar
; CHECK: Type: SHT_PROGBITS
; CHECK: Flags [ (0x6)
; CHECK: SHF_ALLOC
; CHECK: SHF_EXECINSTR
; CHECK: ]
; CHECK: }
; CHECK: Section {
; CHECK: Name: .text._start
; CHECK: Type: SHT_PROGBITS
; CHECK: Flags [ (0x6)
; CHECK: SHF_ALLOC
; CHECK: SHF_EXECINSTR
; CHECK: ]
; CHECK: }
; CHECK: Section {
; CHECK: Name: .rel.text._start
; CHECK: Type: SHT_REL
; CHECK: Flags [ (0x0)
; CHECK: ]
; CHECK: )
; CHECK: }
; CHECK: Relocations [
; CHECK: Section ({{[0-9]+}}) .rel.text.foo {
; CHECK: 0x21 R_386_PC32 memcpy 0x0
; CHECK: }
; Relocation can be against the start of the section or
; the function's symbol itself.
; CHECK: Section ({{[0-9]+}}) .rel.text._start {
; CHECK: 0x13 R_386_PC32 {{.*}}bar 0x0
; CHECK: 0x25 R_386_PC32 {{.*}}foo 0x0
; CHECK: }
; CHECK: ]
; CHECK: Symbols [
; CHECK: Name: bar
; CHECK: Name: foo
; CHECK: Name: _start
; CHECK: Name: memcpy
; CHECK: ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment