116 Commits

Author SHA1 Message Date
Fangrui Song
b77f51f3f1 MCSymbolXOFF: Remove classof
The object file format specific derived classes are used in context
where the type is statically known. We don't use isa/dyn_cast and we
want to eliminate MCSymbol::Kind in the base class.
2025-08-03 18:49:36 -07:00
Fangrui Song
d6c2e53151 MCSymbolXCOFF: Migrate away from classof
The object file format specific derived classes are used in context
where the type is statically known. We don't use isa/dyn_cast and we
want to eliminate MCSymbol::Kind in the base class.
2025-08-03 18:18:44 -07:00
Fangrui Song
1ea085be7c MCSectionXCOFF: Remove classof
The object file format specific derived classes are used in context like
MCStreamer and MCObjectTargetWriter where the type is statically known.
We don't use isa/dyn_cast and we want to eliminate
MCSection::SectionVariant in the base class.
2025-07-26 00:44:05 -07:00
Fangrui Song
244e053b6c MC: Remove llvm/MC/MCFixupKindInfo.h
The file used to define `MCFixupKindInfo`, a simple structure,
which is now in MCAsmBackend.h.
2025-07-05 11:24:11 -07:00
Fangrui Song
9234d07752 MCAssembler: Optimize PCRel fixups
* MCAssembler::evaluateFixup sets MCFixup::PCRel.
* ELFObjectWriter retrieves the bit from the MCFixup argument.
2025-07-03 00:01:53 -07:00
Fangrui Song
7ff0cf6138 MCObjectWriter: Remove the MCAssembler argument from writeObject 2025-05-24 12:55:52 -07:00
Fangrui Song
e373f7a452 MC: Simplify recordRelocation
* Remove the MCAssembler * argument. Change subclasses to use MCAssembler *MCObjectWriter::Asm.
* Remove pure specifier and add an empty implementation
* Change MCFragment * to MCFragment &
2025-05-24 09:54:03 -07:00
Fangrui Song
a8433b88fa MCObjectwriter: Add member variable MCAssembler * and simplify code 2025-05-24 00:11:32 -07:00
Fangrui Song
7ccdc3d5ca [MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol.
This change reduces dependence on MCSymbolRefExpr.
2025-04-05 13:16:25 -07:00
Fangrui Song
dfae1f968e MCValue: Simplify code with getSubSym 2025-03-23 12:22:44 -07:00
Amy Kwan
f31099ce58
[PowerPC][AIX] Emit PowerPC version for XCOFF (#113214)
This PR emits implements the ability to emit the PPC version for both
assembly and object files on AIX.
2024-12-10 11:11:50 -05:00
Fangrui Song
d78d030b31 [MC] Export llvm::XCOFFObjectwriter and access it from MCXCOFFStreamer
Similar to commit 9539a7796094ff5fb59d9c685140ea2e214b945c for
WinCOFFObjectWriter.

Close #100412
2024-10-26 12:26:11 -07:00
Kazu Hirata
edfb6dd3f7
[MC] Avoid repeated hash lookups (NFC) (#110791) 2024-10-02 06:54:24 -07:00
Fangrui Song
219d80bcb7 MCAssembler: Move FileNames and CompilerVersion to MCObjectWriter 2024-07-22 20:20:32 -07:00
Fangrui Song
023c645497 MCObjectWriter: Remove XCOFF specific virtual functions
Add forwarders for now. XCOFFObjectWriter should eventually be exported
like Mach-O/COFF/ELF (commit 70c52b62c5669993e341664a63bfbe5245e32884).
2024-07-22 16:47:45 -07:00
Chen Zheng
f138b33ddd [XCOFF] refactor the XCOFF BeginSymName handling
Fixes #96810
2024-07-22 05:16:20 -04:00
Fangrui Song
9539a77960 [MC] Export llvm::WinCOFFObjectWriter and access it from MCWinCOFFStreamer
Similar to commit 28fcafb50274be2520117eacb0a886adafefe59d (2011) for
MachObjectWriter. MCWinCOFFStreamer can now access WinCOFFObjectWriter
directly without holding object file format specific inforamtion in
MCAssembler (e.g. IncrementalLinkerCompatible).
2024-07-21 12:04:47 -07:00
Dmitriy Chestnykh
345861b186
[MC] Optimize loops in MC (#98114)
https://llvm.org/docs/CodingStandards.html tells us that we should avoid
evaluating `.end()` each time if possible.
2024-07-12 09:48:49 +02:00
Fangrui Song
a7ddd605ca XCOFFObjectWriter: replace the MCAsmLayout parameter with MCAssembler 2024-07-01 17:24:41 -07:00
Fangrui Song
dbf12b2f77 [MC] Remove MCAsmLayout::{getSymbolOffset,getBaseSymbol}
The MCAsmLayout::* forwarders added by
67957a45ee1ec42ae1671cdbfa0d73127346cc95 have all been removed.
2024-07-01 11:51:26 -07:00
Fangrui Song
a40ca78bb9 [MC] Remove MCAsmLayout::{getSectionFileSize,getSectionAddressSize} 2024-07-01 11:27:32 -07:00
Fangrui Song
6b707a8cc1 [MC] Remove the MCAsmLayout parameter from MCObjectWriter::executePostLayoutBinding 2024-07-01 10:47:46 -07:00
Fangrui Song
23e6224374 [MC] Remove the MCAsmLayout parameter from MCObjectWriter::{writeObject,writeSectionData} 2024-07-01 10:04:59 -07:00
Fangrui Song
4289c422a8 [MC] Remove the MCAsmLayout parameter from MCObjectWriter::recordRelocation 2024-06-30 22:13:54 -07:00
Zaara Syeda
6582509daa
[AIX] Handle toc-data offset overflowing 16-bits (#80092)
When the toc-data offset overflows the 16-bits, we can truncate the
value to the 16-bit value as the linker will handle overflow through
fixup code.
2024-03-28 13:55:13 -04:00
Felix (Ting Wang)
5b05870953
[PowerPC] Support local-dynamic TLS relocation on AIX (#66316)
Supports TLS local-dynamic on AIX, generates below sequence of code:

```
.tc foo[TC],foo[TL]@ld # Variable offset, ld relocation specifier
.tc mh[TC],mh[TC]@ml # Module handle for the caller
lwz 3,mh[TC]\(2\) $$ For 64-bit: ld 3,mh[TC]\(2\)
bla .__tls_get_mod # Modifies r0,r3,r4,r5,r11,lr,cr0
#r3 = &TLS for module
lwz 4,foo[TC]\(2\) $$ For 64-bit: ld 4,foo[TC]\(2\)
add 5,3,4 # Compute &foo
.rename mh[TC], "\_$TLSML" # Symbol for the module handle must have the name "_$TLSML"
```

---------

Co-authored-by: tingwang <tingwang@tingwangs-MBP.lan>
Co-authored-by: tingwang <tingwang@tingwangs-MacBook-Pro.local>
2024-03-01 08:09:40 +08:00
stephenpeckham
b1acb7a315
[XCOFF] Add compiler version to an auxiliary symbol table entry (#80162)
C_FILE symbols. To match the behavior of the assembler and the legacy
compiler, this includes using the generic ".file" name for the C_FILE
symbol and generating the actual file name in an auxiliary entry.
2024-02-06 09:08:18 -06:00
Zaara Syeda
a03a6e9964
[AIX] [XCOFF] Add support for common and local common symbols in the TOC (#79530)
This patch adds support for common and local symbols in the TOC for AIX.
Note that we need to update isVirtualSection so as a common symbol in
TOC will have the symbol type XTY_CM and will be initialized when placed
in the TOC so sections with this type are no longer virtual.

---------

Co-authored-by: Zaara Syeda <syzaara@ca.ibm.com>
2024-01-31 16:34:21 -05:00
Kazu Hirata
4a0ccfa865 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-12 21:21:45 -07:00
Fangrui Song
111fcb0df0 [llvm] Fix duplicate word typos. NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 18:25:16 -07:00
Qiu Chaofan
21bea1a208 [PowerPC] Support initial-exec TLS relocation on AIX
Add TLS_IE relocation type to XCOFF writer, and emit code sequence for
initial-exec TLS variables.

Reviewed By: lkail

Differential Revision: https://reviews.llvm.org/D156292
2023-08-30 16:22:16 +08:00
esmeyi
776195865d [XCOFF] Write source language ID and CPU version ID into C_FILE symbol.
Summary: The source language ID and CPU version ID are required by debuggers on AIX. AIX's system assembler determines the source language ID based on the source file's name suffix, and the behavior in this patch is consistent with it.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D155684
2023-07-24 00:35:24 -04:00
Jake Egan
311abf5fc0 Implement -frecord-command-line for XCOFF integrated assembler path
The patch D153600 implemented `-frecord-command-line` for the XCOFF direct assembly path. This patch adds support for the XCOFF integrated assembly path.

Reviewed By: scott.linder

Differential Revision: https://reviews.llvm.org/D154921
2023-07-20 09:45:37 -04:00
Jake Egan
d2884a234a [NFC][XCOFF] Remove curly braces from single line if statement
Missed this detail from D155199.
2023-07-18 23:35:39 -04:00
Jake Egan
ecbc812e0c [NFC][XCOFF] Use common function to calculate file offset
The file offset code is repeated in nearly identical form for every derivation of SectionEntry, so make it into a method in SectionEntry instead.

Reviewed By: scott.linder

Differential Revision: https://reviews.llvm.org/D155199
2023-07-18 22:08:56 -04:00
Amy Kwan
8e0e442c1d [AIX][TLS] Account for local-exec accesses in XCOFFObjectWriter
This is a follow up to D149722 and aims to address https://github.com/llvm/llvm-project/issues/63885.
Local-exec accesses were not previously accounted for in XCOFFObjectWriter.
Specifically, the R_TLS_LE relocation was not previously handled, which lead to
the incorrect value being written for the relocation target.

Within this patch, the value being written is set to the symbol's virtual
address and extra relocation tests are added.

Differential Revision: https://reviews.llvm.org/D155415
2023-07-17 12:15:44 -05:00
esmeyi
2d74cf1f24 [XCOFF] Force recording a relocation for weak symbol label.
Summary: Currently, if there are multiple definitions of the same symbol declared has weak linkage, the linker may choose the wrong one when they are compiled with integrated-as. This patch fixes the issue. If the target symbol is a weak label we must not attempt to resolve the fixup directly. Emit a relocation and leave resolution of the final target address to the linker.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D153839
2023-07-05 01:58:18 -04:00
esmeyi
028a261350 [XCOFF] FixupOffsetInCsect should be 0 for R_REF relocation.
Summary: The FixupOffsetInCsect should be 0 for R_REF relocation since it specifies a nonrelocating reference. Otherwise liker would try to relocate the symbol through its address and an error like following occurred.
```
ld: 0711-547 SEVERE ERROR: Object /tmp/1-2a7ea1.o cannot be processed.
	RLD address 0x65 for section 2 (.data) is
	not contained in the section.
```

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D152777
2023-06-15 01:28:45 -04:00
Akshay Khadse
c9f6912a3a [Coverity] Fix uninitialized scalar members in MC
This change fixes static code analysis errors

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D148814
2023-04-23 15:29:52 +08:00
esmeyi
49dcd08c3d [XCOFF] support the ref directive for object generation.
Summary: A R_REF relocation as a non-relocating reference is required to prevent garbage collection (by the binder) of the ref symbol in object generation.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D144356
2023-03-23 05:09:47 -04:00
Kazu Hirata
398af9b43b [llvm] Use *{Map,Set}::contains (NFC) 2023-03-15 18:06:32 -07:00
Kazu Hirata
b595eb83e5 [llvm] Use *{Set,Map}::contains (NFC) 2023-03-14 18:56:07 -07:00
esmeyi
5ce0a26bd1 [XCOFF] handle the toc-data for object file generation.
Summary: The toc-data feature has been supported for assembly file generation.
         This patch handles the toc-data for object file generation.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D139516
2023-01-11 23:27:47 -05:00
esmeyi
db5b7b3fe2 [XCOFF] Fix the offset error of dwarf sections caused by D137819. 2023-01-10 12:32:13 -05:00
esmeyi
ea6dec1b3a [XCOFF] support the overflow section (only relocation overflow is handled).
Summary: This patch handles relocation field overflows in an XCOFF32 file. (XCOFF64 files may not have overflow section headers.) If a section has more than 65,534 relocation entries or line number entries, both of these fields are set to a value of 65535. In this case, an overflow section header with the s_flags field equal to STYP_OVRFLO is used to contain the relocation and line-number count information. Since line number is not supported, this patch only handles the relocation overflow.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D137819
2023-01-10 02:39:02 -05:00
esmeyi
2e8c7f6527 [XCOFF] adjust the Fixedvalue for R_RBR relocations.
Summary: Currently we get a wrong fixed value for R_RBR relocations when -ffunction-sections enabled. This patch fixes this.

Reviewed By: DiggerLin, shchenz

Differential Revision: https://reviews.llvm.org/D138982
2022-12-15 01:56:53 -05:00
esmeyi
664cbfaf07 [NFC][XCOFF] format XCOFFObjectWriter.cpp 2022-12-04 23:57:33 -05:00
Guillaume Chatelet
e647b4f519 [reland][Alignment][NFC] Use the Align type in MCSection
Differential Revision: https://reviews.llvm.org/D138653
2022-11-24 13:19:18 +00:00
Guillaume Chatelet
3467f9c7d6 Revert D138653 [Alignment][NFC] Use the Align type in MCSection"
This breaks the bolt project.
This reverts commit 409f0dc4a420db1c6b259d5ae965a070c169d930.
2022-11-24 12:42:30 +00:00
Guillaume Chatelet
409f0dc4a4 [Alignment][NFC] Use the Align type in MCSection
Differential Revision: https://reviews.llvm.org/D138653
2022-11-24 12:32:58 +00:00