-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
414 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Gp info | ||
|
||
|
||
Every attribute listed is optional unless explicitly stated. | ||
|
||
## Table of contents | ||
|
||
- [Gp info](#gp-info) | ||
- [Table of contents](#table-of-contents) | ||
- [`section`](#section) | ||
- [Example](#example) | ||
- [Valid values](#valid-values) | ||
- [Default value](#default-value) | ||
- [`offset`](#offset) | ||
- [Example](#example-1) | ||
- [Valid values](#valid-values-1) | ||
- [Default value](#default-value-1) | ||
- [`provide`](#provide) | ||
- [Valid values](#valid-values-2) | ||
- [Default value](#default-value-2) | ||
- [`hidden`](#hidden) | ||
- [Valid values](#valid-values-3) | ||
- [Default value](#default-value-3) | ||
- [`include_if_any`, `include_if_all`, `exclude_if_any` and `exclude_if_all`](#include_if_any-include_if_all-exclude_if_any-and-exclude_if_all) | ||
|
||
## `section` | ||
|
||
The `_gp` symbol will be emitted just before this section. | ||
|
||
### Example | ||
|
||
```yaml | ||
segments: | ||
- name: main | ||
gp_info: | ||
section: .sdata | ||
``` | ||
### Valid values | ||
Non-empty string. | ||
### Default value | ||
`.sdata` | ||
|
||
## `offset` | ||
|
||
An offset into the the section, allowing the `_gp` value to not point to the | ||
start of the section, maximizing the available accessable range using the `$gp` | ||
register. | ||
|
||
### Example | ||
|
||
```yaml | ||
segments: | ||
- name: main | ||
gp_info: | ||
offset: 0x8000 | ||
``` | ||
|
||
### Valid values | ||
|
||
Integers. | ||
|
||
### Default value | ||
|
||
`0x7FF0` | ||
|
||
## `provide` | ||
|
||
If `provide` is enabled then the `_gp` symbol will only be set if it is | ||
referenced by any linked code but is not defined in any object included in the | ||
link. | ||
|
||
See GNU LD documentation for | ||
[`PROVIDE`](https://sourceware.org/binutils/docs/ld/PROVIDE.html). | ||
|
||
This option can be combined with [`hidden`](#hidden). For more info see the GNU | ||
LD documentation for | ||
[`PROVIDE_HIDDEN`](https://sourceware.org/binutils/docs/ld/PROVIDE_005fHIDDEN.html). | ||
|
||
### Valid values | ||
|
||
Bool. | ||
|
||
### Default value | ||
|
||
`False` | ||
|
||
## `hidden` | ||
|
||
Allows defining the `_gp` symbol to be hidden and won't be exported. | ||
|
||
On a more technical sense, the binding of the generated symbol on the elf will | ||
be marked as `LOCAL` instead of `GLOBAL`. | ||
|
||
See GNU LD documentation for | ||
[`HIDDEN`](https://sourceware.org/binutils/docs/ld/HIDDEN.html). | ||
|
||
This option can be combined with [`provide`](#provide). For more info see the | ||
GNU LD documentation for | ||
[`PROVIDE_HIDDEN`](https://sourceware.org/binutils/docs/ld/PROVIDE_005fHIDDEN.html). | ||
|
||
### Valid values | ||
|
||
Bool. | ||
|
||
### Default value | ||
|
||
`False` | ||
|
||
## `include_if_any`, `include_if_all`, `exclude_if_any` and `exclude_if_all` | ||
|
||
These fields allow to conditionally include or exclude a given segment depending | ||
on the current [custom options](custom_options.md). | ||
|
||
Their syntax is the same as their [`file`](file.md#include_if_any) counterparts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* SPDX-FileCopyrightText: © 2024 decompals */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
use serde::Deserialize; | ||
|
||
use crate::{absent_nullable::AbsentNullable, traits::Serial, Settings, SlinkyError}; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] | ||
pub struct GpInfo { | ||
// The relative section to emit the `_gp` symbol | ||
pub section: String, | ||
// An offset into the small data section, used to maximize the range of small data. | ||
pub offset: i32, | ||
|
||
/// Signals if the `_gp` symbol should be wrapped in a `PROVIDE` statement. | ||
/// Can be used with `hidden`. | ||
pub provide: bool, | ||
/// Signals if the `_gp` symbol should be wrapped in a `HIDDEN` statement. | ||
/// Can be used with `provide`. | ||
pub hidden: bool, | ||
|
||
pub include_if_any: Vec<(String, String)>, | ||
pub include_if_all: Vec<(String, String)>, | ||
pub exclude_if_any: Vec<(String, String)>, | ||
pub exclude_if_all: Vec<(String, String)>, | ||
} | ||
|
||
fn gp_info_default_section() -> String { | ||
".sdata".to_string() | ||
} | ||
|
||
const fn gp_info_default_offset() -> i32 { | ||
0x7FF0 | ||
} | ||
|
||
const fn gp_info_default_provide() -> bool { | ||
false | ||
} | ||
|
||
const fn gp_info_default_hidden() -> bool { | ||
false | ||
} | ||
|
||
#[derive(Deserialize, PartialEq, Debug)] | ||
#[serde(deny_unknown_fields)] | ||
pub(crate) struct GpInfoSerial { | ||
#[serde(default)] | ||
pub section: AbsentNullable<String>, | ||
#[serde(default)] | ||
pub offset: AbsentNullable<i32>, | ||
|
||
#[serde(default)] | ||
pub provide: AbsentNullable<bool>, | ||
#[serde(default)] | ||
pub hidden: AbsentNullable<bool>, | ||
|
||
#[serde(default)] | ||
pub include_if_any: AbsentNullable<Vec<(String, String)>>, | ||
#[serde(default)] | ||
pub include_if_all: AbsentNullable<Vec<(String, String)>>, | ||
#[serde(default)] | ||
pub exclude_if_any: AbsentNullable<Vec<(String, String)>>, | ||
#[serde(default)] | ||
pub exclude_if_all: AbsentNullable<Vec<(String, String)>>, | ||
} | ||
|
||
impl Serial for GpInfoSerial { | ||
type Output = GpInfo; | ||
|
||
fn unserialize(self, _settings: &Settings) -> Result<Self::Output, SlinkyError> { | ||
let section = { | ||
let s = self | ||
.section | ||
.get_non_null("section", gp_info_default_section)?; | ||
if s.is_empty() { | ||
return Err(SlinkyError::EmptyValue { | ||
name: "section".to_string(), | ||
}); | ||
} | ||
s | ||
}; | ||
|
||
let offset = self.offset.get_non_null("offset", gp_info_default_offset)?; | ||
|
||
let provide = self | ||
.provide | ||
.get_non_null("provide", gp_info_default_provide)?; | ||
let hidden = self.hidden.get_non_null("hidden", gp_info_default_hidden)?; | ||
|
||
let include_if_any = self | ||
.include_if_any | ||
.get_non_null_not_empty("include_if_any", Vec::new)?; | ||
let include_if_all = self | ||
.include_if_all | ||
.get_non_null_not_empty("include_if_all", Vec::new)?; | ||
let exclude_if_any = self | ||
.exclude_if_any | ||
.get_non_null_not_empty("exclude_if_any", Vec::new)?; | ||
let exclude_if_all = self | ||
.exclude_if_all | ||
.get_non_null_not_empty("exclude_if_all", Vec::new)?; | ||
|
||
Ok(Self::Output { | ||
section, | ||
offset, | ||
provide, | ||
hidden, | ||
include_if_any, | ||
include_if_all, | ||
exclude_if_any, | ||
exclude_if_all, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.