@vigolium/piolium 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/agents/access-auditor.md +300 -0
- package/agents/assumption-breaker.md +154 -0
- package/agents/attack-designer.md +116 -0
- package/agents/code-scanner.md +139 -0
- package/agents/concurrency-auditor.md +238 -0
- package/agents/confirm-writer.md +257 -0
- package/agents/context-reviewer.md +274 -0
- package/agents/cross-verifier.md +165 -0
- package/agents/cve-scout.md +381 -0
- package/agents/env-builder.md +282 -0
- package/agents/env-profiler.md +205 -0
- package/agents/evidence-collector.md +140 -0
- package/agents/finding-grader.md +142 -0
- package/agents/finding-writer.md +148 -0
- package/agents/flow-tracer.md +106 -0
- package/agents/goal-backtracer.md +146 -0
- package/agents/history-miner.md +467 -0
- package/agents/independent-verifier.md +118 -0
- package/agents/intent-mapper.md +183 -0
- package/agents/longshot-collector.md +128 -0
- package/agents/longshot-prober.md +126 -0
- package/agents/patch-auditor.md +73 -0
- package/agents/poc-author.md +124 -0
- package/agents/poc-runner.md +194 -0
- package/agents/probe-lead.md +269 -0
- package/agents/red-challenger.md +101 -0
- package/agents/report-composer.md +208 -0
- package/agents/review-adjudicator.md +216 -0
- package/agents/spec-auditor.md +155 -0
- package/agents/taint-tracer.md +265 -0
- package/agents/test-locator.md +209 -0
- package/agents/threat-modeler.md +132 -0
- package/agents/variant-scanner.md +108 -0
- package/agents/variant-spotter.md +110 -0
- package/bin/piolium.mjs +376 -0
- package/extensions/piolium/_vendor/yaml.bundle.d.mts +6 -0
- package/extensions/piolium/_vendor/yaml.bundle.mjs +139 -0
- package/extensions/piolium/agent-runner.ts +322 -0
- package/extensions/piolium/agents.ts +266 -0
- package/extensions/piolium/audit-state.ts +522 -0
- package/extensions/piolium/bundled-resources.ts +97 -0
- package/extensions/piolium/candidate-scan.ts +966 -0
- package/extensions/piolium/command-target.ts +177 -0
- package/extensions/piolium/console-stream.ts +57 -0
- package/extensions/piolium/export-results.ts +380 -0
- package/extensions/piolium/findings.ts +448 -0
- package/extensions/piolium/heartbeat.ts +182 -0
- package/extensions/piolium/help.ts +234 -0
- package/extensions/piolium/index.ts +1865 -0
- package/extensions/piolium/longshot.ts +530 -0
- package/extensions/piolium/matcher-suggestions.ts +196 -0
- package/extensions/piolium/matcher-utils.ts +83 -0
- package/extensions/piolium/modes/balanced.ts +750 -0
- package/extensions/piolium/modes/confirm-bootstrap.ts +186 -0
- package/extensions/piolium/modes/confirm.ts +697 -0
- package/extensions/piolium/modes/deep.ts +917 -0
- package/extensions/piolium/modes/diff.ts +177 -0
- package/extensions/piolium/modes/lite.ts +540 -0
- package/extensions/piolium/modes/longshot.ts +595 -0
- package/extensions/piolium/modes/merge.ts +204 -0
- package/extensions/piolium/modes/phase-runner.ts +267 -0
- package/extensions/piolium/modes/reinvest.ts +546 -0
- package/extensions/piolium/modes/revisit.ts +279 -0
- package/extensions/piolium/modes.ts +48 -0
- package/extensions/piolium/phase-labels.ts +123 -0
- package/extensions/piolium/phase-status-strip.ts +92 -0
- package/extensions/piolium/prompt-prefix-editor.ts +39 -0
- package/extensions/piolium/providers/anthropic-vertex.ts +836 -0
- package/extensions/piolium/recon.ts +409 -0
- package/extensions/piolium/result-stats.ts +105 -0
- package/extensions/piolium/retry.ts +120 -0
- package/extensions/piolium/scheduler.ts +212 -0
- package/extensions/piolium/secrets.ts +368 -0
- package/extensions/piolium/tools/web-tools.ts +148 -0
- package/package.json +77 -0
- package/skills/agentic-actions-auditor/SKILL.md +327 -0
- package/skills/agentic-actions-auditor/references/action-profiles.md +186 -0
- package/skills/agentic-actions-auditor/references/cross-file-resolution.md +209 -0
- package/skills/agentic-actions-auditor/references/foundations.md +94 -0
- package/skills/agentic-actions-auditor/references/vector-a-env-var-intermediary.md +77 -0
- package/skills/agentic-actions-auditor/references/vector-b-direct-expression-injection.md +83 -0
- package/skills/agentic-actions-auditor/references/vector-c-cli-data-fetch.md +83 -0
- package/skills/agentic-actions-auditor/references/vector-d-pr-target-checkout.md +88 -0
- package/skills/agentic-actions-auditor/references/vector-e-error-log-injection.md +88 -0
- package/skills/agentic-actions-auditor/references/vector-f-subshell-expansion.md +82 -0
- package/skills/agentic-actions-auditor/references/vector-g-eval-of-ai-output.md +91 -0
- package/skills/agentic-actions-auditor/references/vector-h-dangerous-sandbox-configs.md +102 -0
- package/skills/agentic-actions-auditor/references/vector-i-wildcard-allowlists.md +88 -0
- package/skills/audit/SKILL.md +562 -0
- package/skills/audit/assets/icon.svg +7 -0
- package/skills/audit/hooks/scripts/validate_phase_output.py +550 -0
- package/skills/audit/references/adversarial-review.md +148 -0
- package/skills/audit/references/architecture-aware-sast.md +306 -0
- package/skills/audit/references/audit-workflow.md +737 -0
- package/skills/audit/references/chamber-protocol.md +384 -0
- package/skills/audit/references/creative-attack-modes.md +221 -0
- package/skills/audit/references/deep-analysis.md +273 -0
- package/skills/audit/references/domain-attack-playbooks.md +1129 -0
- package/skills/audit/references/knowledge-base-template.md +513 -0
- package/skills/audit/references/real-env-validation.md +191 -0
- package/skills/audit/references/report-templates.md +417 -0
- package/skills/audit/references/triage-and-prereqs.md +134 -0
- package/skills/audit/scripts/consolidate_drafts.py +554 -0
- package/skills/audit/scripts/partition_findings.py +152 -0
- package/skills/audit/scripts/rg-hotspots.sh +121 -0
- package/skills/audit/scripts/stamp_file_state.py +349 -0
- package/skills/code-reviewer/SKILL.md +65 -0
- package/skills/codeql/SKILL.md +281 -0
- package/skills/codeql/references/build-fixes.md +90 -0
- package/skills/codeql/references/diagnostic-query-templates.md +339 -0
- package/skills/codeql/references/extension-yaml-format.md +209 -0
- package/skills/codeql/references/important-only-suite.md +153 -0
- package/skills/codeql/references/language-details.md +207 -0
- package/skills/codeql/references/macos-arm64e-workaround.md +179 -0
- package/skills/codeql/references/performance-tuning.md +111 -0
- package/skills/codeql/references/quality-assessment.md +172 -0
- package/skills/codeql/references/ruleset-catalog.md +63 -0
- package/skills/codeql/references/run-all-suite.md +92 -0
- package/skills/codeql/references/sarif-processing.md +79 -0
- package/skills/codeql/references/threat-models.md +51 -0
- package/skills/codeql/workflows/build-database.md +280 -0
- package/skills/codeql/workflows/create-data-extensions.md +261 -0
- package/skills/codeql/workflows/run-analysis.md +301 -0
- package/skills/differential-review/SKILL.md +220 -0
- package/skills/differential-review/adversarial.md +203 -0
- package/skills/differential-review/methodology.md +234 -0
- package/skills/differential-review/patterns.md +300 -0
- package/skills/differential-review/reporting.md +369 -0
- package/skills/fp-check/SKILL.md +125 -0
- package/skills/fp-check/references/bug-class-verification.md +114 -0
- package/skills/fp-check/references/deep-verification.md +143 -0
- package/skills/fp-check/references/evidence-templates.md +91 -0
- package/skills/fp-check/references/false-positive-patterns.md +115 -0
- package/skills/fp-check/references/gate-reviews.md +27 -0
- package/skills/fp-check/references/standard-verification.md +78 -0
- package/skills/insecure-defaults/SKILL.md +117 -0
- package/skills/insecure-defaults/references/examples.md +409 -0
- package/skills/last30days/SKILL.md +444 -0
- package/skills/sarif-parsing/SKILL.md +483 -0
- package/skills/sarif-parsing/resources/jq-queries.md +162 -0
- package/skills/sarif-parsing/resources/sarif_helpers.py +331 -0
- package/skills/security-threat-model/LICENSE.txt +201 -0
- package/skills/security-threat-model/SKILL.md +81 -0
- package/skills/security-threat-model/agents/openai.yaml +4 -0
- package/skills/security-threat-model/references/prompt-template.md +255 -0
- package/skills/security-threat-model/references/security-controls-and-assets.md +32 -0
- package/skills/semgrep/SKILL.md +212 -0
- package/skills/semgrep/references/rulesets.md +162 -0
- package/skills/semgrep/references/scan-modes.md +110 -0
- package/skills/semgrep/references/scanner-task-prompt.md +140 -0
- package/skills/semgrep/scripts/merge_sarif.py +203 -0
- package/skills/semgrep/workflows/scan-workflow.md +311 -0
- package/skills/semgrep-rule-creator/SKILL.md +168 -0
- package/skills/semgrep-rule-creator/references/quick-reference.md +202 -0
- package/skills/semgrep-rule-creator/references/workflow.md +240 -0
- package/skills/semgrep-rule-variant-creator/SKILL.md +205 -0
- package/skills/semgrep-rule-variant-creator/references/applicability-analysis.md +250 -0
- package/skills/semgrep-rule-variant-creator/references/language-syntax-guide.md +324 -0
- package/skills/semgrep-rule-variant-creator/references/workflow.md +518 -0
- package/skills/sharp-edges/SKILL.md +292 -0
- package/skills/sharp-edges/references/auth-patterns.md +252 -0
- package/skills/sharp-edges/references/case-studies.md +274 -0
- package/skills/sharp-edges/references/config-patterns.md +333 -0
- package/skills/sharp-edges/references/crypto-apis.md +190 -0
- package/skills/sharp-edges/references/lang-c.md +205 -0
- package/skills/sharp-edges/references/lang-csharp.md +285 -0
- package/skills/sharp-edges/references/lang-go.md +270 -0
- package/skills/sharp-edges/references/lang-java.md +263 -0
- package/skills/sharp-edges/references/lang-javascript.md +269 -0
- package/skills/sharp-edges/references/lang-kotlin.md +265 -0
- package/skills/sharp-edges/references/lang-php.md +245 -0
- package/skills/sharp-edges/references/lang-python.md +274 -0
- package/skills/sharp-edges/references/lang-ruby.md +273 -0
- package/skills/sharp-edges/references/lang-rust.md +272 -0
- package/skills/sharp-edges/references/lang-swift.md +287 -0
- package/skills/sharp-edges/references/language-specific.md +588 -0
- package/skills/spec-to-code-compliance/SKILL.md +357 -0
- package/skills/spec-to-code-compliance/resources/COMPLETENESS_CHECKLIST.md +69 -0
- package/skills/spec-to-code-compliance/resources/IR_EXAMPLES.md +417 -0
- package/skills/spec-to-code-compliance/resources/OUTPUT_REQUIREMENTS.md +105 -0
- package/skills/supply-chain-risk-auditor/SKILL.md +67 -0
- package/skills/supply-chain-risk-auditor/resources/results-template.md +41 -0
- package/skills/variant-analysis/METHODOLOGY.md +327 -0
- package/skills/variant-analysis/SKILL.md +142 -0
- package/skills/variant-analysis/resources/codeql/cpp.ql +119 -0
- package/skills/variant-analysis/resources/codeql/go.ql +69 -0
- package/skills/variant-analysis/resources/codeql/java.ql +71 -0
- package/skills/variant-analysis/resources/codeql/javascript.ql +63 -0
- package/skills/variant-analysis/resources/codeql/python.ql +80 -0
- package/skills/variant-analysis/resources/semgrep/cpp.yaml +98 -0
- package/skills/variant-analysis/resources/semgrep/go.yaml +63 -0
- package/skills/variant-analysis/resources/semgrep/java.yaml +61 -0
- package/skills/variant-analysis/resources/semgrep/javascript.yaml +60 -0
- package/skills/variant-analysis/resources/semgrep/python.yaml +72 -0
- package/skills/variant-analysis/resources/variant-report-template.md +75 -0
- package/skills/vuln-report/SKILL.md +137 -0
- package/skills/vuln-report/agents/openai.yaml +4 -0
- package/skills/vuln-report/references/report-template.md +135 -0
- package/skills/wooyun-legacy/SKILL.md +367 -0
- package/skills/wooyun-legacy/references/bank-penetration.md +222 -0
- package/skills/wooyun-legacy/references/checklists/command-execution-checklist.md +119 -0
- package/skills/wooyun-legacy/references/checklists/csrf-checklist.md +74 -0
- package/skills/wooyun-legacy/references/checklists/file-upload-checklist.md +108 -0
- package/skills/wooyun-legacy/references/checklists/info-disclosure-checklist.md +114 -0
- package/skills/wooyun-legacy/references/checklists/logic-flaws-checklist.md +95 -0
- package/skills/wooyun-legacy/references/checklists/misconfig-checklist.md +124 -0
- package/skills/wooyun-legacy/references/checklists/path-traversal-checklist.md +87 -0
- package/skills/wooyun-legacy/references/checklists/rce-checklist.md +93 -0
- package/skills/wooyun-legacy/references/checklists/sql-injection-checklist.md +97 -0
- package/skills/wooyun-legacy/references/checklists/ssrf-checklist.md +99 -0
- package/skills/wooyun-legacy/references/checklists/unauthorized-access-checklist.md +89 -0
- package/skills/wooyun-legacy/references/checklists/weak-password-checklist.md +115 -0
- package/skills/wooyun-legacy/references/checklists/xss-checklist.md +103 -0
- package/skills/wooyun-legacy/references/checklists/xxe-checklist.md +130 -0
- package/skills/wooyun-legacy/references/info-disclosure.md +975 -0
- package/skills/wooyun-legacy/references/logic-flaws.md +721 -0
- package/skills/wooyun-legacy/references/path-traversal.md +1191 -0
- package/skills/wooyun-legacy/references/telecom-penetration.md +156 -0
- package/skills/wooyun-legacy/references/unauthorized-access.md +980 -0
- package/skills/wooyun-legacy/references/xss.md +746 -0
- package/skills/zeroize-audit/SKILL.md +371 -0
- package/skills/zeroize-audit/configs/c.yaml +21 -0
- package/skills/zeroize-audit/configs/default.yaml +128 -0
- package/skills/zeroize-audit/configs/rust.yaml +83 -0
- package/skills/zeroize-audit/prompts/report_template.md +238 -0
- package/skills/zeroize-audit/prompts/system.md +163 -0
- package/skills/zeroize-audit/prompts/task.md +97 -0
- package/skills/zeroize-audit/references/compile-commands.md +231 -0
- package/skills/zeroize-audit/references/detection-strategy.md +191 -0
- package/skills/zeroize-audit/references/ir-analysis.md +252 -0
- package/skills/zeroize-audit/references/mcp-analysis.md +221 -0
- package/skills/zeroize-audit/references/poc-generation.md +470 -0
- package/skills/zeroize-audit/references/rust-zeroization-patterns.md +867 -0
- package/skills/zeroize-audit/schemas/input.json +83 -0
- package/skills/zeroize-audit/schemas/output.json +140 -0
- package/skills/zeroize-audit/tools/analyze_asm.sh +202 -0
- package/skills/zeroize-audit/tools/analyze_cfg.py +381 -0
- package/skills/zeroize-audit/tools/analyze_heap.sh +211 -0
- package/skills/zeroize-audit/tools/analyze_ir_semantic.py +429 -0
- package/skills/zeroize-audit/tools/diff_ir.sh +135 -0
- package/skills/zeroize-audit/tools/diff_rust_mir.sh +189 -0
- package/skills/zeroize-audit/tools/emit_asm.sh +67 -0
- package/skills/zeroize-audit/tools/emit_ir.sh +77 -0
- package/skills/zeroize-audit/tools/emit_rust_asm.sh +178 -0
- package/skills/zeroize-audit/tools/emit_rust_ir.sh +150 -0
- package/skills/zeroize-audit/tools/emit_rust_mir.sh +158 -0
- package/skills/zeroize-audit/tools/extract_compile_flags.py +284 -0
- package/skills/zeroize-audit/tools/generate_poc.py +1329 -0
- package/skills/zeroize-audit/tools/mcp/apply_confidence_gates.py +113 -0
- package/skills/zeroize-audit/tools/mcp/check_mcp.sh +68 -0
- package/skills/zeroize-audit/tools/mcp/normalize_mcp_evidence.py +125 -0
- package/skills/zeroize-audit/tools/scripts/check_llvm_patterns.py +481 -0
- package/skills/zeroize-audit/tools/scripts/check_mir_patterns.py +554 -0
- package/skills/zeroize-audit/tools/scripts/check_rust_asm.py +424 -0
- package/skills/zeroize-audit/tools/scripts/check_rust_asm_aarch64.py +300 -0
- package/skills/zeroize-audit/tools/scripts/check_rust_asm_x86.py +283 -0
- package/skills/zeroize-audit/tools/scripts/find_dangerous_apis.py +375 -0
- package/skills/zeroize-audit/tools/scripts/semantic_audit.py +923 -0
- package/skills/zeroize-audit/tools/track_dataflow.sh +196 -0
- package/skills/zeroize-audit/tools/validate_rust_toolchain.sh +298 -0
- package/skills/zeroize-audit/workflows/phase-0-preflight.md +150 -0
- package/skills/zeroize-audit/workflows/phase-1-source-analysis.md +144 -0
- package/skills/zeroize-audit/workflows/phase-2-compiler-analysis.md +139 -0
- package/skills/zeroize-audit/workflows/phase-3-interim-report.md +46 -0
- package/skills/zeroize-audit/workflows/phase-4-poc-generation.md +46 -0
- package/skills/zeroize-audit/workflows/phase-5-poc-validation.md +136 -0
- package/skills/zeroize-audit/workflows/phase-6-final-report.md +44 -0
- package/skills/zeroize-audit/workflows/phase-7-test-generation.md +42 -0
- package/themes/piolium-srcery.json +94 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# diff_rust_mir.sh — Normalize and diff Rust MIR across optimization levels.
|
|
3
|
+
#
|
|
4
|
+
# Compares MIR output from different optimization levels to detect zeroize-
|
|
5
|
+
# related transformations: drop glue removal, StorageDead elimination, and
|
|
6
|
+
# zeroize call elimination.
|
|
7
|
+
#
|
|
8
|
+
# Exit codes:
|
|
9
|
+
# 0 all files are identical after normalization
|
|
10
|
+
# 1 at least one diff found (or wipe patterns disappeared)
|
|
11
|
+
# 2 argument error
|
|
12
|
+
#
|
|
13
|
+
# Usage (two-file, backward-compatible):
|
|
14
|
+
# diff_rust_mir.sh <O0.mir> <O2.mir>
|
|
15
|
+
#
|
|
16
|
+
# Usage (multi-level — recommended):
|
|
17
|
+
# diff_rust_mir.sh <O0.mir> <O1.mir> <O2.mir> [<O3.mir> ...]
|
|
18
|
+
#
|
|
19
|
+
# Output:
|
|
20
|
+
# - Unified diff for each pair of adjacent files.
|
|
21
|
+
# - For 3+ files, a ZEROIZE PATTERN SUMMARY identifying the first opt level
|
|
22
|
+
# at which patterns disappear.
|
|
23
|
+
#
|
|
24
|
+
# Wipe patterns detected:
|
|
25
|
+
# zeroize::, Zeroize::zeroize, volatile_set_memory, drop_in_place,
|
|
26
|
+
# StorageDead for sensitive locals, ptr::write_bytes
|
|
27
|
+
|
|
28
|
+
set -euo pipefail
|
|
29
|
+
|
|
30
|
+
usage() {
|
|
31
|
+
cat <<'EOF'
|
|
32
|
+
Usage:
|
|
33
|
+
diff_rust_mir.sh <baseline.mir> <file2.mir> [<file3.mir> ...]
|
|
34
|
+
|
|
35
|
+
Compares Rust MIR files across optimization levels. Normalizes away noisy
|
|
36
|
+
metadata (source locations, scope info, storage annotations) and diffs
|
|
37
|
+
the semantic content. Detects disappearance of zeroize-related patterns.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
diff_rust_mir.sh crate.O0.mir crate.O2.mir
|
|
41
|
+
diff_rust_mir.sh crate.O0.mir crate.O1.mir crate.O2.mir crate.O3.mir
|
|
42
|
+
EOF
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if [[ $# -lt 2 ]]; then
|
|
46
|
+
usage
|
|
47
|
+
exit 2
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
for f in "$@"; do
|
|
51
|
+
if [[ ! -f "$f" ]]; then
|
|
52
|
+
echo "diff_rust_mir.sh: missing file: $f" >&2
|
|
53
|
+
exit 2
|
|
54
|
+
fi
|
|
55
|
+
done
|
|
56
|
+
|
|
57
|
+
# ---------------------------------------------------------------------------
|
|
58
|
+
# Normalization: strip noisy metadata that changes between opt levels
|
|
59
|
+
# but is semantically irrelevant for zeroize analysis.
|
|
60
|
+
# ---------------------------------------------------------------------------
|
|
61
|
+
norm() {
|
|
62
|
+
sed -E \
|
|
63
|
+
-e '/^\/\/ WARNING:/d' \
|
|
64
|
+
-e '/^\/\/ MIR for/d' \
|
|
65
|
+
-e 's/scope [0-9]+ at [^ ]+:[0-9]+:[0-9]+/scope N at <loc>/g' \
|
|
66
|
+
-e 's/at [^ ]+\.rs:[0-9]+:[0-9]+/at <loc>/g' \
|
|
67
|
+
-e 's/\/\/ .*$//g' \
|
|
68
|
+
-e '/^\s*$/d'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# ---------------------------------------------------------------------------
|
|
72
|
+
# Pattern detection: Rust MIR zeroize-related constructs
|
|
73
|
+
# ---------------------------------------------------------------------------
|
|
74
|
+
has_zeroize_pattern() {
|
|
75
|
+
grep -qE \
|
|
76
|
+
'zeroize::|Zeroize::zeroize|volatile_set_memory|ptr::write_bytes|drop_in_place.*[Kk]ey|drop_in_place.*[Ss]ecret|drop_in_place.*[Pp]assword|drop_in_place.*[Tt]oken|drop_in_place.*[Nn]once|drop_in_place.*[Ss]eed|drop_in_place.*[Pp]riv|Zeroizing|ZeroizeOnDrop' \
|
|
77
|
+
"$1"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
has_drop_glue() {
|
|
81
|
+
grep -qE 'drop_in_place|drop\(_[0-9]+\)' "$1"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# shellcheck disable=SC2329,SC2317 # invoked indirectly by agent prompts
|
|
85
|
+
has_storage_dead_sensitive() {
|
|
86
|
+
grep -qE 'StorageDead\(_[0-9]+\)' "$1" &&
|
|
87
|
+
grep -qE '(key|secret|password|token|nonce|seed|priv|master|credential)' "$1"
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# ---------------------------------------------------------------------------
|
|
91
|
+
# Setup
|
|
92
|
+
# ---------------------------------------------------------------------------
|
|
93
|
+
FILES=("$@")
|
|
94
|
+
NUM_FILES=${#FILES[@]}
|
|
95
|
+
|
|
96
|
+
TMPDIR_BASE="$(mktemp -d -t za-mir-XXXXXX)"
|
|
97
|
+
trap 'rm -rf "$TMPDIR_BASE"' EXIT
|
|
98
|
+
|
|
99
|
+
NORMFILES=()
|
|
100
|
+
for i in "${!FILES[@]}"; do
|
|
101
|
+
tmp="$TMPDIR_BASE/norm_${i}.mir"
|
|
102
|
+
norm <"${FILES[$i]}" >"$tmp"
|
|
103
|
+
NORMFILES+=("$tmp")
|
|
104
|
+
done
|
|
105
|
+
|
|
106
|
+
# ---------------------------------------------------------------------------
|
|
107
|
+
# Two-file mode: backward-compatible, single diff, no summary.
|
|
108
|
+
# ---------------------------------------------------------------------------
|
|
109
|
+
if [[ $NUM_FILES -eq 2 ]]; then
|
|
110
|
+
diff_rc=0
|
|
111
|
+
diff -u "${NORMFILES[0]}" "${NORMFILES[1]}" || diff_rc=$?
|
|
112
|
+
if [[ $diff_rc -eq 2 ]]; then
|
|
113
|
+
echo "diff_rust_mir.sh: diff failed (internal error)" >&2
|
|
114
|
+
exit 1
|
|
115
|
+
fi
|
|
116
|
+
exit $diff_rc
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
# ---------------------------------------------------------------------------
|
|
120
|
+
# Multi-file mode: pairwise diffs + zeroize pattern summary.
|
|
121
|
+
# ---------------------------------------------------------------------------
|
|
122
|
+
any_diff=0
|
|
123
|
+
|
|
124
|
+
for ((i = 0; i < NUM_FILES - 1; i++)); do
|
|
125
|
+
j=$((i + 1))
|
|
126
|
+
A_LABEL="$(basename "${FILES[$i]}")"
|
|
127
|
+
B_LABEL="$(basename "${FILES[$j]}")"
|
|
128
|
+
echo "=== DIFF File $((i + 1)) ($A_LABEL) vs File $((j + 1)) ($B_LABEL) ==="
|
|
129
|
+
if ! diff -u --label "$A_LABEL" --label "$B_LABEL" \
|
|
130
|
+
"${NORMFILES[$i]}" "${NORMFILES[$j]}"; then
|
|
131
|
+
any_diff=1
|
|
132
|
+
fi
|
|
133
|
+
echo ""
|
|
134
|
+
done
|
|
135
|
+
|
|
136
|
+
# ---------------------------------------------------------------------------
|
|
137
|
+
# Zeroize pattern summary
|
|
138
|
+
# ---------------------------------------------------------------------------
|
|
139
|
+
echo "=== ZEROIZE PATTERN SUMMARY ==="
|
|
140
|
+
first_absent=-1
|
|
141
|
+
for i in "${!NORMFILES[@]}"; do
|
|
142
|
+
LABEL="$(basename "${FILES[$i]}")"
|
|
143
|
+
if has_zeroize_pattern "${NORMFILES[$i]}"; then
|
|
144
|
+
echo " File $((i + 1)) ($LABEL): ZEROIZE CALLS PRESENT"
|
|
145
|
+
else
|
|
146
|
+
echo " File $((i + 1)) ($LABEL): ZEROIZE CALLS ABSENT"
|
|
147
|
+
if [[ $first_absent -eq -1 ]]; then
|
|
148
|
+
first_absent=$i
|
|
149
|
+
fi
|
|
150
|
+
fi
|
|
151
|
+
done
|
|
152
|
+
echo ""
|
|
153
|
+
|
|
154
|
+
# ---------------------------------------------------------------------------
|
|
155
|
+
# Drop glue summary
|
|
156
|
+
# ---------------------------------------------------------------------------
|
|
157
|
+
echo "=== DROP GLUE SUMMARY ==="
|
|
158
|
+
first_drop_absent=-1
|
|
159
|
+
for i in "${!NORMFILES[@]}"; do
|
|
160
|
+
LABEL="$(basename "${FILES[$i]}")"
|
|
161
|
+
if has_drop_glue "${NORMFILES[$i]}"; then
|
|
162
|
+
echo " File $((i + 1)) ($LABEL): DROP GLUE PRESENT"
|
|
163
|
+
else
|
|
164
|
+
echo " File $((i + 1)) ($LABEL): DROP GLUE ABSENT"
|
|
165
|
+
if [[ $first_drop_absent -eq -1 ]]; then
|
|
166
|
+
first_drop_absent=$i
|
|
167
|
+
fi
|
|
168
|
+
fi
|
|
169
|
+
done
|
|
170
|
+
echo ""
|
|
171
|
+
|
|
172
|
+
# ---------------------------------------------------------------------------
|
|
173
|
+
# Verdict
|
|
174
|
+
# ---------------------------------------------------------------------------
|
|
175
|
+
if [[ $first_absent -ne -1 ]]; then
|
|
176
|
+
LABEL="$(basename "${FILES[$first_absent]}")"
|
|
177
|
+
echo "WARNING: Zeroize patterns first disappear at File $((first_absent + 1)) ($LABEL)."
|
|
178
|
+
echo " Evidence: OPTIMIZED_AWAY_ZEROIZE — zeroize calls present at lower opt level(s) but absent here."
|
|
179
|
+
any_diff=1
|
|
180
|
+
elif [[ $first_drop_absent -ne -1 ]]; then
|
|
181
|
+
LABEL="$(basename "${FILES[$first_drop_absent]}")"
|
|
182
|
+
echo "WARNING: Drop glue first disappears at File $((first_drop_absent + 1)) ($LABEL)."
|
|
183
|
+
echo " Evidence: Drop glue present at lower opt level(s) but absent here — sensitive type drop may be inlined or elided."
|
|
184
|
+
any_diff=1
|
|
185
|
+
else
|
|
186
|
+
echo "OK: Zeroize patterns and drop glue present at all opt levels analyzed."
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
exit $any_diff
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Emit assembly for a given translation unit.
|
|
5
|
+
#
|
|
6
|
+
# Usage:
|
|
7
|
+
# emit_asm.sh --cc clang --src path/to/file.c --out /tmp/file.s --opt O2 -- <extra compile args>
|
|
8
|
+
|
|
9
|
+
usage() {
|
|
10
|
+
echo "Usage: $0 --src <file> --out <out.s> [--cc clang] [--opt O0|O1|O2|O3|Os|Oz] -- <extra args>" >&2
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
CC="clang"
|
|
14
|
+
SRC=""
|
|
15
|
+
OUT=""
|
|
16
|
+
OPT="O0"
|
|
17
|
+
|
|
18
|
+
while [[ $# -gt 0 ]]; do
|
|
19
|
+
case "$1" in
|
|
20
|
+
--cc)
|
|
21
|
+
CC="$2"
|
|
22
|
+
shift 2
|
|
23
|
+
;;
|
|
24
|
+
--src)
|
|
25
|
+
SRC="$2"
|
|
26
|
+
shift 2
|
|
27
|
+
;;
|
|
28
|
+
--out)
|
|
29
|
+
OUT="$2"
|
|
30
|
+
shift 2
|
|
31
|
+
;;
|
|
32
|
+
--opt)
|
|
33
|
+
OPT="$2"
|
|
34
|
+
shift 2
|
|
35
|
+
;;
|
|
36
|
+
--)
|
|
37
|
+
shift
|
|
38
|
+
break
|
|
39
|
+
;;
|
|
40
|
+
*)
|
|
41
|
+
echo "Unknown arg: $1" >&2
|
|
42
|
+
usage
|
|
43
|
+
exit 2
|
|
44
|
+
;;
|
|
45
|
+
esac
|
|
46
|
+
done
|
|
47
|
+
|
|
48
|
+
if [[ -z "$SRC" || -z "$OUT" ]]; then
|
|
49
|
+
usage
|
|
50
|
+
exit 2
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
case "$OPT" in
|
|
54
|
+
O0 | O1 | O2 | O3 | Os | Oz) ;;
|
|
55
|
+
*)
|
|
56
|
+
echo "Invalid --opt: $OPT" >&2
|
|
57
|
+
usage
|
|
58
|
+
exit 2
|
|
59
|
+
;;
|
|
60
|
+
esac
|
|
61
|
+
|
|
62
|
+
EXTRA=("$@")
|
|
63
|
+
mkdir -p "$(dirname "$OUT")"
|
|
64
|
+
|
|
65
|
+
"$CC" "-$OPT" -S "$SRC" -o "$OUT" ${EXTRA[@]+"${EXTRA[@]}"}
|
|
66
|
+
|
|
67
|
+
echo "OK: wrote asm to $OUT"
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Emit LLVM IR for a given translation unit.
|
|
5
|
+
#
|
|
6
|
+
# Usage:
|
|
7
|
+
# emit_ir.sh --cc clang --src path/to/file.c --out /tmp/file.ll --opt O2 -- <extra compile args>
|
|
8
|
+
#
|
|
9
|
+
# Notes:
|
|
10
|
+
# - Use `--` to pass through extra include/define flags.
|
|
11
|
+
# - We intentionally do not attempt to parse compile_commands.json here.
|
|
12
|
+
# Your runner should extract the TU command and pass flags after `--`.
|
|
13
|
+
|
|
14
|
+
usage() {
|
|
15
|
+
echo "Usage: $0 --src <file> --out <out.ll> [--cc clang] [--opt O0|O1|O2|O3|Os|Oz] -- <extra args>" >&2
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
CC="clang"
|
|
19
|
+
SRC=""
|
|
20
|
+
OUT=""
|
|
21
|
+
OPT="O0"
|
|
22
|
+
|
|
23
|
+
while [[ $# -gt 0 ]]; do
|
|
24
|
+
case "$1" in
|
|
25
|
+
--cc)
|
|
26
|
+
CC="$2"
|
|
27
|
+
shift 2
|
|
28
|
+
;;
|
|
29
|
+
--src)
|
|
30
|
+
SRC="$2"
|
|
31
|
+
shift 2
|
|
32
|
+
;;
|
|
33
|
+
--out)
|
|
34
|
+
OUT="$2"
|
|
35
|
+
shift 2
|
|
36
|
+
;;
|
|
37
|
+
--opt)
|
|
38
|
+
OPT="$2"
|
|
39
|
+
shift 2
|
|
40
|
+
;;
|
|
41
|
+
--)
|
|
42
|
+
shift
|
|
43
|
+
break
|
|
44
|
+
;;
|
|
45
|
+
*)
|
|
46
|
+
echo "Unknown arg: $1" >&2
|
|
47
|
+
usage
|
|
48
|
+
exit 2
|
|
49
|
+
;;
|
|
50
|
+
esac
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
if [[ -z "$SRC" || -z "$OUT" ]]; then
|
|
54
|
+
usage
|
|
55
|
+
exit 2
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# Normalize OPT -> clang flag
|
|
59
|
+
case "$OPT" in
|
|
60
|
+
O0 | O1 | O2 | O3 | Os | Oz) ;;
|
|
61
|
+
*)
|
|
62
|
+
echo "Invalid --opt: $OPT" >&2
|
|
63
|
+
usage
|
|
64
|
+
exit 2
|
|
65
|
+
;;
|
|
66
|
+
esac
|
|
67
|
+
|
|
68
|
+
# Extra args after --
|
|
69
|
+
EXTRA=("$@")
|
|
70
|
+
|
|
71
|
+
# Ensure output dir exists
|
|
72
|
+
mkdir -p "$(dirname "$OUT")"
|
|
73
|
+
|
|
74
|
+
# Emit IR
|
|
75
|
+
"$CC" "-$OPT" -S -emit-llvm "$SRC" -o "$OUT" ${EXTRA[@]+"${EXTRA[@]}"}
|
|
76
|
+
|
|
77
|
+
echo "OK: wrote IR to $OUT"
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# emit_rust_asm.sh — Emit Rust assembly for zeroize analysis.
|
|
3
|
+
#
|
|
4
|
+
# Exit codes:
|
|
5
|
+
# 0 success
|
|
6
|
+
# 1 build/output failure
|
|
7
|
+
# 2 argument error
|
|
8
|
+
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
|
|
11
|
+
usage() {
|
|
12
|
+
cat <<'EOF'
|
|
13
|
+
Usage:
|
|
14
|
+
emit_rust_asm.sh --manifest <Cargo.toml> --out <path> [options] [-- <extra cargo rustc args>]
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--manifest <file> Cargo manifest path (required)
|
|
18
|
+
--out <path> Output .s file or directory (required)
|
|
19
|
+
--opt <O0|O1|O2|O3> Opt level (default: O2)
|
|
20
|
+
--crate <pkg> Workspace package (-p)
|
|
21
|
+
--bin <target> Build only a specific bin target
|
|
22
|
+
--lib Build only the lib target
|
|
23
|
+
--target <triple> Cross-compile target (e.g. x86_64-unknown-linux-gnu)
|
|
24
|
+
--intel-syntax Emit Intel syntax instead of AT&T (default: AT&T)
|
|
25
|
+
--help Show this help text
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
emit_rust_asm.sh --manifest Cargo.toml --opt O2 --out /tmp/crate.O2.s
|
|
29
|
+
emit_rust_asm.sh --manifest Cargo.toml --opt O0 --out /tmp/asm/ --lib
|
|
30
|
+
emit_rust_asm.sh --manifest Cargo.toml --out /tmp/crate.O2.s --crate mycrate --target x86_64-unknown-linux-gnu
|
|
31
|
+
EOF
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
die_arg() {
|
|
35
|
+
echo "emit_rust_asm.sh: $*" >&2
|
|
36
|
+
exit 2
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
die_run() {
|
|
40
|
+
echo "emit_rust_asm.sh: $*" >&2
|
|
41
|
+
exit 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
require_value() {
|
|
45
|
+
local opt="$1"
|
|
46
|
+
local val="${2-}"
|
|
47
|
+
[[ -n "$val" ]] || die_arg "missing value for ${opt}"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
MANIFEST=""
|
|
51
|
+
OUT=""
|
|
52
|
+
OPT="O2"
|
|
53
|
+
CRATE=""
|
|
54
|
+
BIN_TARGET=""
|
|
55
|
+
LIB_TARGET=false
|
|
56
|
+
TARGET_TRIPLE=""
|
|
57
|
+
INTEL_SYNTAX=false
|
|
58
|
+
EXTRA_ARGS=()
|
|
59
|
+
|
|
60
|
+
while [[ $# -gt 0 ]]; do
|
|
61
|
+
case "$1" in
|
|
62
|
+
--manifest)
|
|
63
|
+
require_value "$1" "${2-}"
|
|
64
|
+
MANIFEST="$2"
|
|
65
|
+
shift 2
|
|
66
|
+
;;
|
|
67
|
+
--out)
|
|
68
|
+
require_value "$1" "${2-}"
|
|
69
|
+
OUT="$2"
|
|
70
|
+
shift 2
|
|
71
|
+
;;
|
|
72
|
+
--opt)
|
|
73
|
+
require_value "$1" "${2-}"
|
|
74
|
+
OPT="$2"
|
|
75
|
+
shift 2
|
|
76
|
+
;;
|
|
77
|
+
--crate)
|
|
78
|
+
require_value "$1" "${2-}"
|
|
79
|
+
CRATE="$2"
|
|
80
|
+
shift 2
|
|
81
|
+
;;
|
|
82
|
+
--bin)
|
|
83
|
+
require_value "$1" "${2-}"
|
|
84
|
+
BIN_TARGET="$2"
|
|
85
|
+
shift 2
|
|
86
|
+
;;
|
|
87
|
+
--lib)
|
|
88
|
+
LIB_TARGET=true
|
|
89
|
+
shift
|
|
90
|
+
;;
|
|
91
|
+
--target)
|
|
92
|
+
require_value "$1" "${2-}"
|
|
93
|
+
TARGET_TRIPLE="$2"
|
|
94
|
+
shift 2
|
|
95
|
+
;;
|
|
96
|
+
--intel-syntax)
|
|
97
|
+
INTEL_SYNTAX=true
|
|
98
|
+
shift
|
|
99
|
+
;;
|
|
100
|
+
--help | -h)
|
|
101
|
+
usage
|
|
102
|
+
exit 0
|
|
103
|
+
;;
|
|
104
|
+
--)
|
|
105
|
+
shift
|
|
106
|
+
EXTRA_ARGS=("$@")
|
|
107
|
+
break
|
|
108
|
+
;;
|
|
109
|
+
*)
|
|
110
|
+
die_arg "unknown argument: $1"
|
|
111
|
+
;;
|
|
112
|
+
esac
|
|
113
|
+
done
|
|
114
|
+
|
|
115
|
+
[[ -n "$MANIFEST" ]] || die_arg "--manifest is required"
|
|
116
|
+
[[ -n "$OUT" ]] || die_arg "--out is required"
|
|
117
|
+
[[ -f "$MANIFEST" ]] || die_run "manifest not found: $MANIFEST"
|
|
118
|
+
[[ -n "$BIN_TARGET" && "$LIB_TARGET" == true ]] && die_arg "--bin and --lib are mutually exclusive"
|
|
119
|
+
|
|
120
|
+
case "$OPT" in
|
|
121
|
+
O0) LEVEL="0" ;;
|
|
122
|
+
O1) LEVEL="1" ;;
|
|
123
|
+
O2) LEVEL="2" ;;
|
|
124
|
+
O3) LEVEL="3" ;;
|
|
125
|
+
*) die_arg "unsupported opt level: $OPT (use O0, O1, O2, O3)" ;;
|
|
126
|
+
esac
|
|
127
|
+
|
|
128
|
+
OUT_IS_FILE=false
|
|
129
|
+
if [[ "$OUT" == *.s || "$OUT" == *.asm ]]; then
|
|
130
|
+
OUT_IS_FILE=true
|
|
131
|
+
mkdir -p "$(dirname "$OUT")"
|
|
132
|
+
else
|
|
133
|
+
mkdir -p "$OUT"
|
|
134
|
+
fi
|
|
135
|
+
|
|
136
|
+
CARGO_ARGS=(+nightly rustc --manifest-path "$MANIFEST")
|
|
137
|
+
[[ -n "$CRATE" ]] && CARGO_ARGS+=("-p" "$CRATE")
|
|
138
|
+
[[ -n "$BIN_TARGET" ]] && CARGO_ARGS+=("--bin" "$BIN_TARGET")
|
|
139
|
+
[[ "$LIB_TARGET" == true ]] && CARGO_ARGS+=("--lib")
|
|
140
|
+
[[ -n "$TARGET_TRIPLE" ]] && CARGO_ARGS+=("--target" "$TARGET_TRIPLE")
|
|
141
|
+
|
|
142
|
+
RUSTC_FLAGS=(--emit=asm -C "opt-level=$LEVEL")
|
|
143
|
+
[[ "$INTEL_SYNTAX" == true ]] && RUSTC_FLAGS+=(-C "llvm-args=-x86-asm-syntax=intel")
|
|
144
|
+
|
|
145
|
+
TARGET_DIR="${TMPDIR:-/tmp}/zeroize_rust_asm_${LEVEL}_$$"
|
|
146
|
+
rm -rf "$TARGET_DIR"
|
|
147
|
+
mkdir -p "$TARGET_DIR"
|
|
148
|
+
|
|
149
|
+
echo "=== emit_rust_asm.sh ==="
|
|
150
|
+
echo "manifest: $MANIFEST"
|
|
151
|
+
echo "opt: $OPT"
|
|
152
|
+
echo "target: $TARGET_DIR"
|
|
153
|
+
echo "output: $OUT"
|
|
154
|
+
[[ -n "$TARGET_TRIPLE" ]] && echo "triple: $TARGET_TRIPLE"
|
|
155
|
+
[[ "$INTEL_SYNTAX" == true ]] && echo "syntax: intel"
|
|
156
|
+
|
|
157
|
+
if ! CARGO_TARGET_DIR="$TARGET_DIR" cargo "${CARGO_ARGS[@]}" \
|
|
158
|
+
"${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}" \
|
|
159
|
+
-- "${RUSTC_FLAGS[@]}"; then
|
|
160
|
+
die_run "cargo rustc failed for opt=${OPT}"
|
|
161
|
+
fi
|
|
162
|
+
|
|
163
|
+
declare -a ASM_FILES=()
|
|
164
|
+
while IFS= read -r file; do
|
|
165
|
+
ASM_FILES+=("$file")
|
|
166
|
+
done < <(find "$TARGET_DIR" -type f -name "*.s" | LC_ALL=C sort)
|
|
167
|
+
|
|
168
|
+
[[ "${#ASM_FILES[@]}" -gt 0 ]] || die_run "no .s files found under $TARGET_DIR"
|
|
169
|
+
|
|
170
|
+
if [[ "$OUT_IS_FILE" == true ]]; then
|
|
171
|
+
: >"$OUT"
|
|
172
|
+
for file in "${ASM_FILES[@]}"; do
|
|
173
|
+
cat "$file" >>"$OUT"
|
|
174
|
+
done
|
|
175
|
+
[[ -s "$OUT" ]] || die_run "emitted assembly is empty: $OUT"
|
|
176
|
+
else
|
|
177
|
+
cp "${ASM_FILES[@]}" "$OUT/"
|
|
178
|
+
fi
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# emit_rust_ir.sh — Emit Rust LLVM IR for zeroize analysis.
|
|
3
|
+
#
|
|
4
|
+
# Exit codes:
|
|
5
|
+
# 0 success
|
|
6
|
+
# 1 build/output failure
|
|
7
|
+
# 2 argument error
|
|
8
|
+
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
|
|
11
|
+
usage() {
|
|
12
|
+
cat <<'EOF'
|
|
13
|
+
Usage:
|
|
14
|
+
emit_rust_ir.sh --manifest <Cargo.toml> --out <path> [options] [-- <extra cargo rustc args>]
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--manifest <file> Cargo manifest path (required)
|
|
18
|
+
--out <path> Output .ll file (required)
|
|
19
|
+
--opt <O0|O1|O2|O3> Opt level (default: O2)
|
|
20
|
+
--crate <pkg> Workspace package (-p)
|
|
21
|
+
--bin <target> Build only a specific bin target
|
|
22
|
+
--lib Build only the lib target
|
|
23
|
+
--help Show this help text
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
emit_rust_ir.sh --manifest Cargo.toml --opt O0 --out /tmp/crate.O0.ll
|
|
27
|
+
emit_rust_ir.sh --manifest Cargo.toml --opt O2 --bin cli --out /tmp/cli.O2.ll
|
|
28
|
+
EOF
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
die_arg() {
|
|
32
|
+
echo "emit_rust_ir.sh: $*" >&2
|
|
33
|
+
exit 2
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
die_run() {
|
|
37
|
+
echo "emit_rust_ir.sh: $*" >&2
|
|
38
|
+
exit 1
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
require_value() {
|
|
42
|
+
local opt="$1"
|
|
43
|
+
local val="${2-}"
|
|
44
|
+
[[ -n "$val" ]] || die_arg "missing value for ${opt}"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
MANIFEST=""
|
|
48
|
+
OUT=""
|
|
49
|
+
OPT="O2"
|
|
50
|
+
CRATE=""
|
|
51
|
+
BIN_TARGET=""
|
|
52
|
+
LIB_TARGET=false
|
|
53
|
+
EXTRA_ARGS=()
|
|
54
|
+
|
|
55
|
+
while [[ $# -gt 0 ]]; do
|
|
56
|
+
case "$1" in
|
|
57
|
+
--manifest)
|
|
58
|
+
require_value "$1" "${2-}"
|
|
59
|
+
MANIFEST="$2"
|
|
60
|
+
shift 2
|
|
61
|
+
;;
|
|
62
|
+
--out)
|
|
63
|
+
require_value "$1" "${2-}"
|
|
64
|
+
OUT="$2"
|
|
65
|
+
shift 2
|
|
66
|
+
;;
|
|
67
|
+
--opt)
|
|
68
|
+
require_value "$1" "${2-}"
|
|
69
|
+
OPT="$2"
|
|
70
|
+
shift 2
|
|
71
|
+
;;
|
|
72
|
+
--crate)
|
|
73
|
+
require_value "$1" "${2-}"
|
|
74
|
+
CRATE="$2"
|
|
75
|
+
shift 2
|
|
76
|
+
;;
|
|
77
|
+
--bin)
|
|
78
|
+
require_value "$1" "${2-}"
|
|
79
|
+
BIN_TARGET="$2"
|
|
80
|
+
shift 2
|
|
81
|
+
;;
|
|
82
|
+
--lib)
|
|
83
|
+
LIB_TARGET=true
|
|
84
|
+
shift
|
|
85
|
+
;;
|
|
86
|
+
--help | -h)
|
|
87
|
+
usage
|
|
88
|
+
exit 0
|
|
89
|
+
;;
|
|
90
|
+
--)
|
|
91
|
+
shift
|
|
92
|
+
EXTRA_ARGS=("$@")
|
|
93
|
+
break
|
|
94
|
+
;;
|
|
95
|
+
*)
|
|
96
|
+
die_arg "unknown argument: $1"
|
|
97
|
+
;;
|
|
98
|
+
esac
|
|
99
|
+
done
|
|
100
|
+
|
|
101
|
+
[[ -n "$MANIFEST" ]] || die_arg "--manifest is required"
|
|
102
|
+
[[ -n "$OUT" ]] || die_arg "--out is required"
|
|
103
|
+
[[ -f "$MANIFEST" ]] || die_run "manifest not found: $MANIFEST"
|
|
104
|
+
[[ -n "$BIN_TARGET" && "$LIB_TARGET" == true ]] && die_arg "--bin and --lib are mutually exclusive"
|
|
105
|
+
[[ "$OUT" == *.ll ]] || die_arg "--out must be a .ll file path"
|
|
106
|
+
|
|
107
|
+
case "$OPT" in
|
|
108
|
+
O0) LEVEL="0" ;;
|
|
109
|
+
O1) LEVEL="1" ;;
|
|
110
|
+
O2) LEVEL="2" ;;
|
|
111
|
+
O3) LEVEL="3" ;;
|
|
112
|
+
*) die_arg "unsupported opt level: $OPT (use O0, O1, O2, O3)" ;;
|
|
113
|
+
esac
|
|
114
|
+
|
|
115
|
+
mkdir -p "$(dirname "$OUT")"
|
|
116
|
+
|
|
117
|
+
CARGO_ARGS=(+nightly rustc --manifest-path "$MANIFEST")
|
|
118
|
+
[[ -n "$CRATE" ]] && CARGO_ARGS+=("-p" "$CRATE")
|
|
119
|
+
[[ -n "$BIN_TARGET" ]] && CARGO_ARGS+=("--bin" "$BIN_TARGET")
|
|
120
|
+
[[ "$LIB_TARGET" == true ]] && CARGO_ARGS+=("--lib")
|
|
121
|
+
|
|
122
|
+
TARGET_DIR="${TMPDIR:-/tmp}/zeroize_rust_ir_${LEVEL}_$$"
|
|
123
|
+
rm -rf "$TARGET_DIR"
|
|
124
|
+
mkdir -p "$TARGET_DIR"
|
|
125
|
+
|
|
126
|
+
echo "=== emit_rust_ir.sh ==="
|
|
127
|
+
echo "manifest: $MANIFEST"
|
|
128
|
+
echo "opt: $OPT"
|
|
129
|
+
echo "target: $TARGET_DIR"
|
|
130
|
+
echo "output: $OUT"
|
|
131
|
+
|
|
132
|
+
if ! CARGO_TARGET_DIR="$TARGET_DIR" cargo "${CARGO_ARGS[@]}" \
|
|
133
|
+
${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} \
|
|
134
|
+
-- --emit=llvm-ir -C opt-level="$LEVEL"; then
|
|
135
|
+
die_run "cargo rustc failed for opt=${OPT}"
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
declare -a LL_FILES=()
|
|
139
|
+
while IFS= read -r file; do
|
|
140
|
+
LL_FILES+=("$file")
|
|
141
|
+
done < <(find "$TARGET_DIR" -type f -name "*.ll" | LC_ALL=C sort)
|
|
142
|
+
|
|
143
|
+
[[ "${#LL_FILES[@]}" -gt 0 ]] || die_run "no .ll files found under $TARGET_DIR"
|
|
144
|
+
|
|
145
|
+
: >"$OUT"
|
|
146
|
+
for file in "${LL_FILES[@]}"; do
|
|
147
|
+
cat "$file" >>"$OUT"
|
|
148
|
+
done
|
|
149
|
+
|
|
150
|
+
[[ -s "$OUT" ]] || die_run "emitted IR is empty: $OUT"
|