Skip to content

Commit 94d4a8d

Browse files
authored
fix(kernel): eliminate build warnings (#2155)
Restrict FUSE DAX inspection helpers to test builds and remove stale accessors that no longer participate in production paths. Keep mixed-map PFN classification and initram root attachment semantics explicit without carrying unused state in default builds. Apply the x86_64 noexecstack policy to both kernel link passes so the final ELF advertises a non-executable GNU stack and no longer relies on deprecated linker inference. Signed-off-by: longjin <longjin@dragonos.org>
1 parent 59365fa commit 94d4a8d

7 files changed

Lines changed: 16 additions & 31 deletions

File tree

kernel/src/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ifeq ($(UNWIND_ENABLE), yes)
2424
RUSTFLAGS += -Cforce-unwind-tables -Clink-arg=-Wl,eh_frame.ld -Cpanic=unwind
2525
endif
2626

27+
LDFLAGS_X86_64 = -z noexecstack
28+
2729
CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell pwd)/include
2830

2931
ifeq ($(ARCH), x86_64)
@@ -104,7 +106,7 @@ endif
104106

105107
__link_x86_64_kernel:
106108
@echo "Linking kernel..."
107-
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T arch/x86_64/link.lds --no-relax
109+
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_X86_64) $(LDFLAGS_UNWIND) -o kernel ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T arch/x86_64/link.lds --no-relax
108110
# 生成kallsyms
109111
current_dir=$(pwd)
110112

@@ -117,7 +119,7 @@ __link_x86_64_kernel:
117119
# 重新链接
118120
@echo "Re-Linking kernel..."
119121
@echo $(shell find . -name "*.o")
120-
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T arch/x86_64/link.lds --no-relax
122+
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_X86_64) $(LDFLAGS_UNWIND) -o kernel ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T arch/x86_64/link.lds --no-relax
121123
@echo "Generating kernel ELF file..."
122124
# 生成内核文件
123125
ifeq ($(UNWIND_ENABLE), yes)

kernel/src/filesystem/fuse/conn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ impl FusePendingState {
648648
})?
649649
}
650650

651+
#[cfg(test)]
651652
pub(crate) fn wait_result_with_kind(
652653
&self,
653654
) -> Result<(Result<FusePendingResult, SystemError>, FuseCompletionKind), SystemError> {

kernel/src/filesystem/fuse/inode.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ use super::{
4444
use super::{
4545
private_data::FuseOpenPrivateData,
4646
virtiofs::dax::{
47-
DaxAdmissionGuard, DaxAdmissionState, DaxMappingOwner, DaxRangeAllocator, OwnedToken,
48-
ReclaimCandidate, ReclaimToken, DAX_RANGE_SIZE,
47+
DaxAdmissionGuard, DaxAdmissionState, DaxRangeAllocator, OwnedToken, ReclaimCandidate,
48+
ReclaimToken, DAX_RANGE_SIZE,
4949
},
5050
};
5151

@@ -201,28 +201,16 @@ impl DaxMappingTree {
201201
}
202202

203203
impl DaxMapping {
204-
pub(crate) fn file_offset(&self) -> u64 {
205-
self.file_offset
206-
}
207-
208204
pub(crate) fn window_offset(&self) -> usize {
209205
self.token.window_offset()
210206
}
211207

212208
pub(crate) fn writable(&self) -> bool {
213209
self.writable.load(Ordering::Acquire)
214210
}
215-
216-
pub(crate) fn owner(&self) -> DaxMappingOwner {
217-
self.token.owner()
218-
}
219211
}
220212

221213
impl DaxAccessGuard {
222-
pub(crate) fn mapping(&self) -> &Arc<DaxMapping> {
223-
&self.mapping
224-
}
225-
226214
fn checked_window_offset(&self, offset: usize, len: usize) -> Result<usize, SystemError> {
227215
let end = offset.checked_add(len).ok_or(SystemError::EOVERFLOW)?;
228216
if end > DAX_RANGE_SIZE {
@@ -970,14 +958,6 @@ impl FuseNode {
970958
result
971959
}
972960

973-
pub(crate) fn dax_mapping_for_offset(&self, offset: u64) -> Option<Arc<DaxMapping>> {
974-
self.dax_mappings
975-
.read()
976-
.mappings
977-
.get(&Self::dax_aligned_offset(offset))
978-
.cloned()
979-
}
980-
981961
pub(crate) fn dax_file_size(&self) -> Result<usize, SystemError> {
982962
usize::try_from(self.cached_or_fetch_metadata()?.size.max(0))
983963
.map_err(|_| SystemError::EOVERFLOW)

kernel/src/filesystem/fuse/virtiofs/dax.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ impl AllocationToken {
241241
self.index * DAX_RANGE_SIZE
242242
}
243243

244+
#[cfg(test)]
244245
pub(crate) fn len(&self) -> usize {
245246
DAX_RANGE_SIZE
246247
}
@@ -270,6 +271,7 @@ impl OwnedToken {
270271
self.index * DAX_RANGE_SIZE
271272
}
272273

274+
#[cfg(test)]
273275
pub(crate) fn len(&self) -> usize {
274276
DAX_RANGE_SIZE
275277
}
@@ -292,17 +294,14 @@ impl OwnedToken {
292294
}
293295

294296
impl ReclaimCandidate {
297+
#[cfg(test)]
295298
pub(crate) fn window_offset(&self) -> usize {
296299
self.index * DAX_RANGE_SIZE
297300
}
298301

299302
pub(crate) fn owner(&self) -> DaxMappingOwner {
300303
self.owner
301304
}
302-
303-
pub(crate) fn generation(&self) -> u64 {
304-
self.generation
305-
}
306305
}
307306

308307
impl ReclaimToken {
@@ -314,6 +313,7 @@ impl ReclaimToken {
314313
DAX_RANGE_SIZE
315314
}
316315

316+
#[cfg(test)]
317317
pub(crate) fn owner(&self) -> DaxMappingOwner {
318318
self.owner
319319
}
@@ -753,6 +753,7 @@ impl DaxRangeAllocator {
753753
cleaned
754754
}
755755

756+
#[cfg(test)]
756757
pub(crate) fn finish_shutdown(&self) -> Result<(), SystemError> {
757758
let mut state = self.state.lock_irqsave();
758759
let snapshot = state.snapshot();

kernel/src/mm/ucontext/inner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl InnerAddressSpace {
441441
match LockedVMA::classify_present_pfn(&mut page_manager_guard, paddr, vm_flags)
442442
{
443443
PresentPfn::Managed(page) => Some(page),
444-
PresentPfn::External(_) => None,
444+
PresentPfn::External => None,
445445
}
446446
};
447447
let Some(page) = page else {

kernel/src/mm/ucontext/vma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::*;
88
#[derive(Debug)]
99
pub enum PresentPfn {
1010
Managed(Arc<Page>),
11-
External(PhysAddr),
11+
External,
1212
}
1313

1414
/// A locked VMA (Virtual Memory Area)
@@ -50,7 +50,7 @@ impl LockedVMA {
5050
vm_flags.contains(VmFlags::VM_MIXEDMAP),
5151
"unmanaged PFN {paddr:?} installed in a non-mixed VMA"
5252
);
53-
PresentPfn::External(paddr)
53+
PresentPfn::External
5454
}
5555

5656
pub fn new(vma: VMA) -> Arc<Self> {

kernel/src/process/namespace/mnt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub struct MntNamespace {
139139
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
140140
pub(crate) enum RootMountAttachment {
141141
/// Linux's initial rootfs has no parent and cannot be pivoted.
142+
#[cfg(feature = "initram")]
142143
Unattached,
143144
/// The visible root is mounted on the hidden initial rootfs anchor.
144145
Attached,

0 commit comments

Comments
 (0)