Skip to content

Commit

Permalink
Allow mixing assembler sources in gcc (#41)
Browse files Browse the repository at this point in the history
This change allows us to specify source files that have assembler
(potentially with preprocessor commands) in between the C / C++ source
files.
  • Loading branch information
lhchavez authored Jan 24, 2023
1 parent 4cd267a commit 45cde84
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.rootfs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ FROM rootfs-setup AS rootfs-build
RUN /src/mkroot

FROM setup AS runtime
RUN wget --quiet https://github.com/omegaup/libinteractive/releases/download/v2.0.25/libinteractive.jar \
RUN wget --quiet https://github.com/omegaup/libinteractive/releases/download/v2.0.29/libinteractive.jar \
-O /usr/share/java/libinteractive.jar

RUN ln -s /opt/nodejs/bin/node /usr/bin/node && \
Expand Down
49 changes: 29 additions & 20 deletions src/jail/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,131 +222,121 @@ impl JailOptions {
seccomp_profile_name = String::from("gcc");
execve_args.extend([
String::from("/usr/bin/gcc-10"),
String::from("-xc"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c11"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::C11Clang => {
seccomp_profile_name = String::from("clang");
execve_args.extend([
String::from("/usr/bin/clang-10"),
String::from("-xc"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c11"),
String::from("-O3"),
String::from("-march=native"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp03GCC => {
seccomp_profile_name = String::from("gcc");
execve_args.extend([
String::from("/usr/bin/g++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++03"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp03Clang => {
seccomp_profile_name = String::from("clang");
execve_args.extend([
String::from("/usr/bin/clang++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++03"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp | args::Language::Cpp11 | args::Language::Cpp11GCC => {
seccomp_profile_name = String::from("gcc");
execve_args.extend([
String::from("/usr/bin/g++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++11"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp11Clang => {
seccomp_profile_name = String::from("clang");
execve_args.extend([
String::from("/usr/bin/clang++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++11"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp17GCC => {
seccomp_profile_name = String::from("gcc");
execve_args.extend([
String::from("/usr/bin/g++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++17"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp17Clang => {
seccomp_profile_name = String::from("clang");
execve_args.extend([
String::from("/usr/bin/clang++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++17"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp20GCC => {
seccomp_profile_name = String::from("gcc");
execve_args.extend([
String::from("/usr/bin/g++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++20"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Cpp20Clang => {
seccomp_profile_name = String::from("clang");
execve_args.extend([
String::from("/usr/bin/clang++-10"),
String::from("-xc++"),
String::from("-o"),
String::from(args.compile_target),
String::from("-std=c++20"),
String::from("-O2"),
]);
execve_args.extend(compile_sources.iter().map(|s| s.clone()));
add_sources(&mut execve_args, "-xc++", compile_sources);
execve_args.push(String::from("-lm"));
}
args::Language::Pascal => {
Expand Down Expand Up @@ -831,3 +821,22 @@ impl JailOptions {
})
}
}

fn add_sources(execve_args: &mut Vec<String>, lang_flag: &str, compile_sources: &Vec<String>) {
let mut needs_flag = true;
for s in compile_sources.iter() {
if s.ends_with(".S") {
execve_args.extend([String::from("-xassembler-with-cpp"), s.clone()]);
needs_flag = true;
} else if s.ends_with(".s") {
execve_args.extend([String::from("-xassembler"), s.clone()]);
needs_flag = true;
} else {
if needs_flag {
execve_args.push(String::from(lang_flag));
needs_flag = false;
}
execve_args.push(s.clone());
}
}
}

0 comments on commit 45cde84

Please sign in to comment.