Skip to content

Commit a5fb0ad

Browse files
committed
Removed the use of Patmos-specific ELF symbol type 'STT_CODE'.
Replaced it with 'STT_FUNC', meaning subfunctions should be treated like other functions.
1 parent 75acd79 commit a5fb0ad

File tree

10 files changed

+65
-28
lines changed

10 files changed

+65
-28
lines changed

include/llvm/MC/MCDirectives.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ enum MCSymbolAttr {
4242
MCSA_WeakDefinition, ///< .weak_definition (MachO)
4343
MCSA_WeakReference, ///< .weak_reference (MachO)
4444
MCSA_WeakDefAutoPrivate, ///< .weak_def_can_be_hidden (MachO)
45-
46-
// Patmos-specific directives
47-
MCSA_ELF_TypeCode ///< .type _foo, STT_CODE
4845
};
4946

5047
enum MCAssemblerFlag {

include/llvm/Object/ELFObjectFile.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ error_code ELFObjectFile<ELFT>::getSymbolFileOffset(DataRefImpl Symb,
261261
Result = ESec ? ESec->sh_offset : UnknownAddressOrSize;
262262
return object_error::success;
263263
case ELF::STT_FUNC:
264-
case ELF::STT_CODE:
265264
case ELF::STT_OBJECT:
266265
case ELF::STT_NOTYPE:
267266
Result = ESym->st_value + (ESec ? ESec->sh_offset : 0);
@@ -294,7 +293,6 @@ error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
294293
Result = ESec ? ESec->sh_addr : UnknownAddressOrSize;
295294
return object_error::success;
296295
case ELF::STT_FUNC:
297-
case ELF::STT_CODE:
298296
case ELF::STT_OBJECT:
299297
case ELF::STT_NOTYPE:
300298
bool IsRelocatable;
@@ -386,7 +384,7 @@ error_code ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Symb,
386384
Result |= SymbolRef::SF_Absolute;
387385

388386
if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION ||
389-
ESym->getType() == ELF::STT_CODE || ESym == &*EF.begin_symbols())
387+
ESym == &*EF.begin_symbols())
390388
Result |= SymbolRef::SF_FormatSpecific;
391389

392390
if (EF.getSymbolTableIndex(ESym) == ELF::SHN_UNDEF)

include/llvm/Support/ELF.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,6 @@ enum {
343343
R_PATMOS_CFLI_PCREL = 12
344344
};
345345

346-
// Patmos symbol types.
347-
enum {
348-
// processor-specific symbol type: 13-15
349-
350-
// Code region cache-able by the method cache. this is similar to STT_FUNC,
351-
// but is intended for sub-sets of functions and not entire functions.
352-
STT_CODE = 13
353-
};
354-
355-
356346
// X86_64 relocations.
357347
enum {
358348
R_X86_64_NONE = 0,

lib/MC/MCAsmStreamer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
434434
case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
435435
case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
436436
case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
437-
case MCSA_ELF_TypeCode: /// .type _foo, STT_CODE
438437
if (!MAI->hasDotTypeDotSizeDirective())
439438
return false; // Symbol attribute not supported
440439
OS << "\t.type\t" << *Symbol << ','
@@ -448,7 +447,6 @@ bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
448447
case MCSA_ELF_TypeCommon: OS << "common"; break;
449448
case MCSA_ELF_TypeNoType: OS << "no_type"; break;
450449
case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
451-
case MCSA_ELF_TypeCode: OS << "code"; break;
452450
}
453451
EmitEOL();
454452
return true;

lib/MC/MCELF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void MCELF::SetType(MCSymbolData &SD, unsigned Type) {
3737
assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
3838
Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
3939
Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
40-
Type == ELF::STT_GNU_IFUNC || Type == ELF::STT_CODE);
40+
Type == ELF::STT_GNU_IFUNC);
4141

4242
uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
4343
SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
@@ -48,7 +48,7 @@ unsigned MCELF::GetType(const MCSymbolData &SD) {
4848
assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
4949
Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
5050
Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
51-
Type == ELF::STT_GNU_IFUNC || Type == ELF::STT_CODE);
51+
Type == ELF::STT_GNU_IFUNC);
5252
return Type;
5353
}
5454

lib/MC/MCELFStreamer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
220220
ELF::STT_FUNC));
221221
break;
222222

223-
case MCSA_ELF_TypeCode:
224-
MCELF::SetType(SD, ELF::STT_CODE);
225-
break;
226-
227223
case MCSA_ELF_TypeIndFunction:
228224
MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
229225
ELF::STT_GNU_IFUNC));

lib/MC/MCMachOStreamer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
244244
switch (Attribute) {
245245
case MCSA_Invalid:
246246
case MCSA_ELF_TypeFunction:
247-
case MCSA_ELF_TypeCode:
248247
case MCSA_ELF_TypeIndFunction:
249248
case MCSA_ELF_TypeObject:
250249
case MCSA_ELF_TypeTLS:

lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
548548
.Case("notype", MCSA_ELF_TypeNoType)
549549
.Case("gnu_unique_object", MCSA_ELF_TypeGnuUniqueObject)
550550
.Case("gnu_indirect_function", MCSA_ELF_TypeIndFunction)
551-
.Case("code", MCSA_ELF_TypeCode)
552551
.Default(MCSA_Invalid);
553552
} else
554553
return TokError("expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "

lib/Target/Patmos/PatmosAsmPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ void PatmosAsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) {
8080
// create new end symbol
8181
CurrCodeEnd = OutContext.CreateTempSymbol();
8282

83-
// mark the symbol as method-cache-cacheable code
84-
OutStreamer.EmitSymbolAttribute(SymStart, MCSA_ELF_TypeCode);
83+
// mark subfunction labels as function labels
84+
OutStreamer.EmitSymbolAttribute(SymStart, MCSA_ELF_TypeFunction);
8585

8686
// emit a .size directive
8787
EmitDotSize(SymStart, CurrCodeEnd);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; RUN: llc < %s -mpatmos-max-subfunction-size=32 | FileCheck %s
2+
; RUN: llc < %s -mpatmos-max-subfunction-size=32 -filetype=obj -o %t -mforce-block-labels;\
3+
; RUN: llvm-objdump %t -d -t | FileCheck %s --check-prefix OBJ
4+
; END.
5+
;//////////////////////////////////////////////////////////////////////////////////////////////////
6+
;
7+
; Tests that assembly and object outputs give subfunction labels the `STT_FUNC` symbol type.
8+
;
9+
; Using the "CHECK" filecheck prefix, we ensure assembly output adds the '@function' attribute to subfunctions.
10+
; Using the "OBJ" filecheck prefix, we ensure that the labels of the subfunctions are local ('l') and functions ('F') in the symbol table.
11+
;
12+
;//////////////////////////////////////////////////////////////////////////////////////////////////
13+
14+
; CHECK: .type main,@function
15+
; CHECK: main:
16+
; OBJ: main:
17+
define i32 @main() {
18+
entry:
19+
; First 24 bytes
20+
%0 = call i32 asm "
21+
.inline_1:
22+
li $0 = 5001 # Long arithmetic, 8 bytes each
23+
add $0 = $0, 5002
24+
add $0 = $0, 5003
25+
", "=r"
26+
()
27+
28+
; CHECK: .type {{.LBB0_[0-9]}},@function
29+
; OBJ: [[INLINE1:.LBB0_[0-9]]]:
30+
; Then 12 bytes
31+
%1 = call i32 asm "
32+
.inline_2:
33+
add $0 = $1, 4
34+
add $0 = $0, 5
35+
add $0 = $0, 6
36+
", "=r, r"
37+
(i32 %0)
38+
39+
; CHECK: .type {{.LBB0_[0-9]}},@function
40+
; OBJ: [[INLINE2:.LBB0_[0-9]]]:
41+
; Then another 20 bytes
42+
%2 = call i32 asm "
43+
.inline_3:
44+
add $0 = $1, 7
45+
add $0 = $0, 8
46+
add $0 = $0, 9
47+
", "=r, r"
48+
(i32 %1)
49+
50+
; CHECK: .type {{.LBB0_[0-9]}},@function
51+
; OBJ: [[INLINE3:.LBB0_[0-9]]]:
52+
%3 = sub i32 %2, 15045
53+
ret i32 %3 ; =0
54+
}
55+
56+
; The following checks the type of the labels in the symbol table
57+
; OBJ: l F .text {{([[:xdigit:]]{8})}} [[INLINE1]]
58+
; OBJ: l F .text {{([[:xdigit:]]{8})}} [[INLINE2]]
59+
; OBJ: l F .text {{([[:xdigit:]]{8})}} [[INLINE3]]
60+
; OBJ: g F .text {{([[:xdigit:]]{8})}} main

0 commit comments

Comments
 (0)