Skip to content

Commit 7b7c8ce

Browse files
committed
Add noexport attr to symbols.txt
Rename `auto_force_active` to `export_all`. This is a better solution to code_merging, as individual functions can be marked `noexport`.
1 parent 1614997 commit 7b7c8ce

File tree

10 files changed

+42
-30
lines changed

10 files changed

+42
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "decomp-toolkit"
33
description = "Yet another GameCube/Wii decompilation toolkit."
44
authors = ["Luke Street <luke@street.dev>"]
55
license = "MIT OR Apache-2.0"
6-
version = "0.7.1"
6+
version = "0.7.2"
77
edition = "2021"
88
publish = false
99
repository = "https://github.com/encounter/decomp-toolkit"

src/cmd/dol.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ pub struct ProjectConfig {
228228
/// Fills gaps between symbols to avoid linker realignment.
229229
#[serde(default = "bool_true", skip_serializing_if = "is_true")]
230230
pub fill_gaps: bool,
231-
/// Marks all emitted symbols as "force active" to prevent the linker from removing them.
231+
/// Marks all emitted symbols as "exported" to prevent the linker from removing them.
232232
#[serde(default = "bool_true", skip_serializing_if = "is_true")]
233-
pub auto_force_active: bool,
233+
pub export_all: bool,
234234
}
235235

236236
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
@@ -248,7 +248,7 @@ pub struct ModuleConfig {
248248
pub symbols: Option<PathBuf>,
249249
#[serde(with = "path_slash_serde_option", default, skip_serializing_if = "is_default")]
250250
pub map: Option<PathBuf>,
251-
/// Forces the given symbols to be active in the linker script.
251+
/// Forces the given symbols to be active (exported) in the linker script.
252252
#[serde(default, skip_serializing_if = "is_default")]
253253
pub force_active: Vec<String>,
254254
#[serde(skip_serializing_if = "is_default")]
@@ -397,7 +397,7 @@ fn apply_selfile(obj: &mut ObjInfo, buf: &[u8]) -> Result<()> {
397397
section,
398398
size: existing_symbol.size,
399399
size_known: existing_symbol.size_known,
400-
flags: ObjSymbolFlagSet(existing_symbol.flags.0 | ObjSymbolFlags::ForceActive),
400+
flags: ObjSymbolFlagSet(existing_symbol.flags.0 | ObjSymbolFlags::Exported),
401401
kind: existing_symbol.kind,
402402
align: existing_symbol.align,
403403
data_kind: existing_symbol.data_kind,
@@ -412,7 +412,7 @@ fn apply_selfile(obj: &mut ObjInfo, buf: &[u8]) -> Result<()> {
412412
demangled_name: symbol.demangled_name.clone(),
413413
address: address as u64,
414414
section,
415-
flags: ObjSymbolFlagSet(ObjSymbolFlags::Global | ObjSymbolFlags::ForceActive),
415+
flags: ObjSymbolFlagSet(ObjSymbolFlags::Global | ObjSymbolFlags::Exported),
416416
..*symbol
417417
},
418418
false,
@@ -574,7 +574,7 @@ fn update_symbols(
574574
name,
575575
address: rel_reloc.addend as u64,
576576
section: Some(target_section_index),
577-
flags: ObjSymbolFlagSet(ObjSymbolFlags::ForceActive.into()),
577+
flags: ObjSymbolFlagSet(ObjSymbolFlags::Exported.into()),
578578
..Default::default()
579579
})?;
580580
}
@@ -862,7 +862,7 @@ fn split_write_obj(
862862
entry,
863863
};
864864
for (unit, split_obj) in module.obj.link_order.iter().zip(&split_objs) {
865-
let out_obj = write_elf(split_obj, config.auto_force_active)?;
865+
let out_obj = write_elf(split_obj, config.export_all)?;
866866
let out_path = obj_dir.join(obj_path_for_unit(&unit.name));
867867
out_config.units.push(OutputUnit {
868868
object: out_path.clone(),
@@ -1766,7 +1766,7 @@ fn config(args: ConfigArgs) -> Result<()> {
17661766
common_start: None,
17671767
symbols_known: false,
17681768
fill_gaps: true,
1769-
auto_force_active: true,
1769+
export_all: true,
17701770
};
17711771

17721772
let mut modules = Vec::<(u32, ModuleConfig)>::new();

src/obj/symbols.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ flags! {
3434
Weak,
3535
Common,
3636
Hidden,
37-
ForceActive,
37+
/// Force symbol to be exported (force active)
38+
Exported,
3839
/// Symbol isn't referenced by any relocations
3940
RelocationIgnore,
4041
/// Symbol won't be written to symbols file
4142
NoWrite,
4243
/// Symbol was stripped from the original object,
4344
/// but is still useful for common BSS matching.
4445
Stripped,
46+
/// Disable automatic export of symbol
47+
NoExport,
4548
}
4649
}
4750

@@ -78,7 +81,7 @@ impl ObjSymbolFlagSet {
7881
pub fn is_hidden(&self) -> bool { self.0.contains(ObjSymbolFlags::Hidden) }
7982

8083
#[inline]
81-
pub fn is_force_active(&self) -> bool { self.0.contains(ObjSymbolFlags::ForceActive) }
84+
pub fn is_exported(&self) -> bool { self.0.contains(ObjSymbolFlags::Exported) }
8285

8386
#[inline]
8487
pub fn is_relocation_ignore(&self) -> bool { self.0.contains(ObjSymbolFlags::RelocationIgnore) }
@@ -89,6 +92,9 @@ impl ObjSymbolFlagSet {
8992
#[inline]
9093
pub fn is_stripped(&self) -> bool { self.0.contains(ObjSymbolFlags::Stripped) }
9194

95+
#[inline]
96+
pub fn is_no_export(&self) -> bool { self.0.contains(ObjSymbolFlags::NoExport) }
97+
9298
#[inline]
9399
pub fn set_scope(&mut self, scope: ObjSymbolScope) {
94100
match scope {
@@ -113,20 +119,21 @@ impl ObjSymbolFlagSet {
113119
#[inline]
114120
pub fn set_force_active(&mut self, value: bool) {
115121
if value {
116-
self.0 |= ObjSymbolFlags::ForceActive;
122+
self.0 = (self.0 & !ObjSymbolFlags::NoExport) | ObjSymbolFlags::Exported;
117123
} else {
118-
self.0 &= !ObjSymbolFlags::ForceActive;
124+
self.0 &= !ObjSymbolFlags::Exported;
119125
}
120126
}
121127

122128
/// Special flags to keep when merging symbols.
123129
#[inline]
124130
pub fn keep_flags(&self) -> FlagSet<ObjSymbolFlags> {
125131
self.0
126-
& (ObjSymbolFlags::ForceActive
132+
& (ObjSymbolFlags::Exported
127133
| ObjSymbolFlags::NoWrite
128134
| ObjSymbolFlags::RelocationIgnore
129-
| ObjSymbolFlags::Stripped)
135+
| ObjSymbolFlags::Stripped
136+
| ObjSymbolFlags::NoExport)
130137
}
131138
}
132139

src/util/comment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl ToWriter for CommentSym {
249249
}
250250

251251
impl CommentSym {
252-
pub fn from(symbol: &ObjSymbol, force_active: bool) -> Self {
252+
pub fn from(symbol: &ObjSymbol, export_all: bool) -> Self {
253253
let align = match symbol.align {
254254
Some(align) => align,
255255
None => {
@@ -277,8 +277,9 @@ impl CommentSym {
277277
}
278278
let mut active_flags = 0;
279279
if !symbol.flags.is_stripped()
280-
&& (symbol.flags.is_force_active()
281-
|| (force_active
280+
&& (symbol.flags.is_exported()
281+
|| (export_all
282+
&& !symbol.flags.is_no_export()
282283
&& matches!(symbol.kind, ObjSymbolKind::Function | ObjSymbolKind::Object)))
283284
{
284285
active_flags |= 0x8;

src/util/config.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn parse_symbol_line(line: &str, obj: &mut ObjInfo) -> Result<Option<ObjSymb
8585
ObjSymbol { name, demangled_name, address: addr as u64, section, ..Default::default() };
8686
// TODO move somewhere common
8787
if symbol.name.starts_with("..") {
88-
symbol.flags.0 |= ObjSymbolFlags::ForceActive;
88+
symbol.flags.0 |= ObjSymbolFlags::Exported;
8989
}
9090
let attrs = captures["attrs"].split(' ');
9191
for attr in attrs {
@@ -128,7 +128,7 @@ pub fn parse_symbol_line(line: &str, obj: &mut ObjInfo) -> Result<Option<ObjSymb
128128
symbol.flags.0 |= ObjSymbolFlags::Hidden;
129129
}
130130
"force_active" => {
131-
symbol.flags.0 |= ObjSymbolFlags::ForceActive;
131+
symbol.flags.0 |= ObjSymbolFlags::Exported;
132132
}
133133
"stripped" => {
134134
symbol.flags.0 |= ObjSymbolFlags::Stripped;
@@ -147,6 +147,9 @@ pub fn parse_symbol_line(line: &str, obj: &mut ObjInfo) -> Result<Option<ObjSymb
147147
let addr = SectionAddress::new(section.unwrap(), symbol.address as u32);
148148
obj.blocked_ranges.insert(addr, addr.address + symbol.size as u32);
149149
}
150+
"noexport" => {
151+
symbol.flags.0 |= ObjSymbolFlags::NoExport;
152+
}
150153
_ => bail!("Unknown symbol attribute '{attr}'"),
151154
}
152155
}
@@ -281,6 +284,9 @@ where W: Write + ?Sized {
281284
write!(w, " noreloc")?;
282285
}
283286
}
287+
if symbol.flags.is_no_export() {
288+
write!(w, " noexport")?;
289+
}
284290
writeln!(w)?;
285291
Ok(())
286292
}

src/util/elf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ where P: AsRef<Path> {
346346
Ok(obj)
347347
}
348348

349-
pub fn write_elf(obj: &ObjInfo, force_active: bool) -> Result<Vec<u8>> {
349+
pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
350350
let mut out_data = Vec::new();
351351
let mut writer = object::write::elf::Writer::new(Endianness::Big, false, &mut out_data);
352352

@@ -540,7 +540,7 @@ pub fn write_elf(obj: &ObjInfo, force_active: bool) -> Result<Vec<u8>> {
540540
out_symbols.push(OutSymbol { index, sym });
541541
symbol_map[symbol_index] = Some(index.0);
542542
if let Some(comment_data) = &mut comment_data {
543-
CommentSym::from(symbol, force_active).to_writer_static(comment_data, Endian::Big)?;
543+
CommentSym::from(symbol, export_all).to_writer_static(comment_data, Endian::Big)?;
544544
}
545545
}
546546

src/util/lcf.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ pub fn generate_ldscript(
6363

6464
let mut force_active = force_active.to_vec();
6565
for symbol in obj.symbols.iter() {
66-
if symbol.flags.is_force_active() && symbol.flags.is_global() && !symbol.flags.is_no_write()
67-
{
66+
if symbol.flags.is_exported() && symbol.flags.is_global() && !symbol.flags.is_no_write() {
6867
force_active.push(symbol.name.clone());
6968
}
7069
}
@@ -98,8 +97,7 @@ pub fn generate_ldscript_partial(
9897

9998
let mut force_active = force_active.to_vec();
10099
for symbol in obj.symbols.iter() {
101-
if symbol.flags.is_force_active() && symbol.flags.is_global() && !symbol.flags.is_no_write()
102-
{
100+
if symbol.flags.is_exported() && symbol.flags.is_global() && !symbol.flags.is_no_write() {
103101
force_active.push(symbol.name.clone());
104102
}
105103
}

src/util/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ fn add_symbol(obj: &mut ObjInfo, symbol_entry: &SymbolEntry, section: Option<usi
823823
};
824824
// TODO move somewhere common
825825
if symbol_entry.name.starts_with("..") {
826-
flags |= ObjSymbolFlags::ForceActive;
826+
flags |= ObjSymbolFlags::Exported;
827827
}
828828
if symbol_entry.unused {
829829
flags |= ObjSymbolFlags::Stripped;

src/util/split.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ fn add_padding_symbols(obj: &mut ObjInfo) -> Result<()> {
563563
size: next_symbol_address - addr as u64,
564564
size_known: true,
565565
flags: ObjSymbolFlagSet(
566-
ObjSymbolFlags::Local | ObjSymbolFlags::ForceActive | ObjSymbolFlags::NoWrite,
566+
ObjSymbolFlags::Local | ObjSymbolFlags::Exported | ObjSymbolFlags::NoWrite,
567567
),
568568
kind: match section.kind {
569569
ObjSectionKind::Code => ObjSymbolKind::Function,
@@ -616,7 +616,7 @@ fn add_padding_symbols(obj: &mut ObjInfo) -> Result<()> {
616616
flags: ObjSymbolFlagSet(
617617
ObjSymbolFlags::Global
618618
| ObjSymbolFlags::Hidden
619-
| ObjSymbolFlags::ForceActive
619+
| ObjSymbolFlags::Exported
620620
| ObjSymbolFlags::NoWrite,
621621
),
622622
kind: match section.kind {

0 commit comments

Comments
 (0)